Schiarizzi

java permutations using recursion

Feb 15th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public static void permutate(ArrayList<String> a){
  2. //create a combined string of the array list
  3. String tempStr = "";
  4. for(int i = 0; i < a.size(); i++){
  5. tempStr = tempStr + a.get(i);
  6. }
  7. doThings("",tempStr);
  8. }
  9.  
  10. public static void doThings(String str1, String str2){
  11. //do all of the things to the other things at the time with the stuff
  12. if (str2.length() <= 1)
  13. System.out.println(str1 + str2);
  14. else
  15. for (int i = 0; i < str2.length(); i++) {
  16.  
  17. String tempStr = str2.substring(0, i) + str2.substring(i + 1);
  18.  
  19. doThings(str1 + str2.charAt(i), tempStr);
  20.  
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment