View Single Post
Old Jan 18th, 2008, 11:42 PM   #6
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Recursive permutation of string

I fixed it:

Java Syntax (Toggle Plain Text)
  1. private static void permute(char[] str, int low, int high) {
  2. if (low == high) {
  3. System.out.println(str);
  4. } else {
  5. for (int i = low; i <= high; i++) {
  6. char[] x = charArrayWithSwappedChars(str, low, i);
  7. permute(x, low + 1, high);
  8. }
  9. }
  10. }

Is there a way to do this without making a copy of the char array each loop iteration?

Last edited by titaniumdecoy; Jan 18th, 2008 at 11:55 PM.
titaniumdecoy is online now   Reply With Quote