I fixed it:
private static void permute(char[] str, int low, int high) {
if (low == high) {
System.out.println(str);
} else {
for (int i = low; i <= high; i++) {
char[] x = charArrayWithSwappedChars(str, low, i);
permute(x, low + 1, high);
}
}
}
Is there a way to do this without making a copy of the char array each loop iteration?