... printPass(data, next, moveItem); // output pass of algorithm
23           }
24        }
25
26        // print a pass of the algorithm
27        public static void printPass(int[] data, int pass, int index) {
28           System.out.printf("after pass %2d: ", pass);
29
30           // output elements till swapped item
31           for (int i = 0; i < index; i++) {
32              System.out.printf("%d  ", data[i]);
33           }
34
35           System.out.printf("%d* ", data[index]); // indicate swap
36
37           // finish outputting array
38           for (int i = index + 1; i < data.length; i++) {
39              System.out.printf("%d  ", data[i]);
40           }
41
42           System.out.printf("%n                           "); // for alignment
43
44           // indicate amount of array that’s sorted
45           for (int i = 0; i <= pass; i++) {
46              System.out.print("--  ");
47           }
48           System.out.println();
49        }
50
51        public static void main(String[] ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.