June 2017
Beginner
1296 pages
69h 23m
English
... [] data, int first, int second) {
27 int temporary = data[first]; // store first in temporary
28 data[first] = data[second]; // replace first with second
29 data[second] = temporary; // put temporary in second
30 }
31
32 // print a pass of the algorithm
33 private static void printPass(int[] data, int pass, int index) {
34 System.out.printf("after pass %2d: ", pass);
35
36 // output elements till selected item
37 for (int i = 0; i < index; i++) {
38 System.out.printf("%d ", data[i]);
39 }
40
41 System.out.printf("%d* ", data[index]); // indicate swap
42
43 // finish outputting array
44 for (int i = index + 1; i < data.length; i++) {
45 System.out.printf("%d ", data[i]);
46 }
47
48 System.out.printf("%n "); // for alignment
49
50 // indicate amount ...Read now
Unlock full access