Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jan 18th, 2008, 10:04 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Recursive permutation of string

This is not homework. It is an exercise out of a textbook I used last year which I am reviewing. I am trying to write a recursive algorithm to reverse a character array. I wrote the code below which works, except that it prints out each permutation multiple times, and I can't figure out how to prevent that from happening. Please advise...

Java Syntax (Toggle Plain Text)
  1. public class RecursivePermutation {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. String str = "abc";
  6. permute(str);
  7.  
  8. }
  9.  
  10. public static void permute(String str) {
  11. permute(str.toCharArray(), 0, str.length() - 1);
  12. }
  13.  
  14. private static void permute(char[] str, int low, int high) {
  15. [b]