@Test public void sort() { int n = 5; DutchFlag flag = new DutchFlag(5); System.out.println(flag); DutchFlagSorter.sort(flag, 5); System.out.println(flag); 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);  }