编写下列声明的历程:
public void permute(String str);
private void permute (char[] str, int low, int high);
第一个历程是驱动程序,调用第二个历程,第二个历程显式str字符串的所有排列。
public class one1_6 {
public void permute(String str) {
char [] strArr = str.toCharArray();
permute(strArr, 0, strArr.length);
}
private void permute(char [] str, int low, int high) {
if(low == high) {
String s = " ";
for(int i = 0; i< high; i++) {
s += str[i];
}
System.out.println(s);
}
else {
for(int i = 0; i < high; i++) {
char temp = str[low];
str[low] = str[i];
str[i] = temp;
permute(str, low+1, high);
}
}
}
public static void main(String[] args) {
one1_6 s = new one1_6();
s.permute("abc");
}
}