1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| public class SortMain { private static KySort sorter; private int[] a;
private SortMain(int... values) { a = values; }
public static void main(String[] args) { setSorter(new QuickSort()); SortMain arr; arr = new SortMain(5, 4, 3, 2, 1, 0); arr.display(); arr.kySort(); arr.display(); System.out.println("--------"); arr = new SortMain(54, 35, 48, 36, 27, 12, 44, 44, 8, 14, 26, 17, 28); arr.display(); arr.kySort(); arr.display(); System.out.println("--------"); arr = new SortMain(32, 103, 24, 88, 95, 70, 97, 15, 102, 6, 79, 46, 51, 37, 93, 108, 9, 58, 53, 58, 79, 36, 58, 91, 78, 58, 61, 81); arr.display(); arr.kySort(); arr.display(); }
private static void setSorter(KySort sorter) { SortMain.sorter = sorter; }
private void display() { for (int i : a) { System.out.print(i + " "); } System.out.println(); }
private void kySort() { sorter.kySort(a, a.length); } }
|