显示字符串的全排列:
1 public static void AllSequenceofString(String string){ 2 if(string == null) 3 return; 4 char[] chars = string.toCharArray(); 5 Permutation(chars,0); 6 } 7 private static void Permutation(char[] chars, int index) { 8 // TODO Auto-generated method stub 9 if(index == chars.length){ 10 for(int i=0;i<chars.length;i++){ 11 System.out.print(chars[i]); 12 } 13 System.out.println(); 14 } 15 else{ 16 for(int i = index ; i < chars.length;i++){ 17 char temp = chars[i]; 18 chars[i] = chars[index]; 19 chars[index] = temp; 20 Permutation(chars,index+1); 21 temp = chars[index]; 22 chars[index] = chars[i]; 23 chars[i] = temp; 24 } 25 } 26 }