Skip to content

Instantly share code, notes, and snippets.

Created March 25, 2013 22:40
Show Gist options
  • Save anonymous/5241508 to your computer and use it in GitHub Desktop.
Save anonymous/5241508 to your computer and use it in GitHub Desktop.
Dutch Flag Problem
public static void dutchFlagSort(char[] inputArray) {
int iii = 0;
int jjj = -1;
int kkk = inputArray.length;
while (iii < kkk) {
if (inputArray[iii] == 'B') {
char temp = inputArray[--kkk];
inputArray[kkk] = inputArray[iii];
inputArray[iii] = temp;
} else if (inputArray[iii] == 'W') {
iii++;
} else {
char temp = inputArray[++jjj];
inputArray[jjj] = inputArray[iii];
inputArray[iii] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment