数据结构与算法分析Java语言描述课后1.6
作者:互联网
编写下列声明的历程:
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");
}
}
标签:1.6,Java,课后,int,void,high,low,str,permute 来源: https://blog.csdn.net/weixin_43222122/article/details/89526023