@Test(timeout = 200) public void testSort() { int N = 1000; for (int i = 0; i < N; i++) { for (int j = 0; j < 10; j++) { DutchFlag flag = new DutchFlag(i); DutchFlagSorter.sort(flag, i); Assert.assertTrue(flag.isSort()); } } }
public static void sort(DutchFlag flag, int n) { int i = 0, j = n - 1; for (int k = 0; k <= j;) { if (flag.color(k) == 1) { k++; } else if (flag.color(k) == 0) { flag.swap(i++, k++); } else { flag.swap(k, j--); } } }
DutchFlagSorter { public static void sort(DutchFlag flag, int n) { int i = 0, j = n - 1; for (int k = 0; k <= j;) { if (flag.color(k) == 1) { k++; } else if (flag.color(k) == 0) { flag.swap(i++, k++); } else { flag.swap(k, j--); } } } }
DutchFlagSorter { public static void sort(DutchFlag flag, int n) { int i = 0, j = n - 1; for (int k = 0; k <= j;) { if (flag.color(k) == 1) { k++; } else if (flag.color(k) == 0) { flag.swap(i++, k++); } else { flag.swap(k, j--); } } }  }
DutchFlagSorter { public static void sort(DutchFlag flag, int n) { int i = 0, j = n - 1; for (int k = 0; k <= j;) { if (flag.color(k) == 1) { k++; } else if (flag.color(k) == 0) { flag.swap(i++, k++); } else { flag.swap(k, j--); } } }  static void sort(DutchFlag flag, int n); }
DutchFlagSorter { public static void sort(DutchFlag flag, int n) { int i = 0, j = n - 1; for (int k = 0; k <= j;) { if (flag.color(k) == 1) { k++; } else if (flag.color(k) == 0) { flag.swap(i++, k++); } else { flag.swap(k, j--); } } }  static void sort(DutchFlag flag, int n);  }