/**
 * A class for printing partially sorted arrays.
 *
 * @author Mark Young (A00000000)
 */
public class PrintTrace {

    /**
     * Print the elements of an array in a nice table.
     *
     * @param arr   the array to print
     */
    public static void printArray(int[] arr) {
        printArray(arr, 0, arr.length);
    }

    /** number of numbers printed per line */
    private static final int PER_LINE = 8;

    /** number of spaces per number */
    private static final int SPACES = 80 / PER_LINE;

    /** format string for numbers */
    private static final String NUM_FORMAT = "%" + SPACES + "d";

    /** format string for place fillers */
    private static final String STR_FORMAT = "%" + SPACES + "s";

    /**
     * Print an array showing only the numbers in one part of it.
     * Numbers before the starting point/after the ending point
     * are replaced with "filler".
     *
     * @param arr   the array to print
     * @param lo    positions less than lo are "filled"
     * @param hi    positions hi and greater are "filled"
     */
    public static void printArray(int[] arr, int lo, int hi) {
        int thisLine = 0;
    	for (int i = 0; i < arr.length; i++) {
           if (thisLine == PER_LINE) {
              System.out.println();
              thisLine = 0;
           }
           if (lo <= i && i < hi) {
              System.out.printf(NUM_FORMAT, arr[i]);
           } else {
              System.out.printf(STR_FORMAT, "...");
           }
           ++thisLine;
    	}
        System.out.println();
    }

}

