C++链接:字符串的排列组合问题_NEOMc的博客-CSDN博客
char[] t1 = new char[]{'a', 'b', 'c', 'd'};
// char[] t1 = new char[]{'a', 'b', 'c'};
permutation(t1, 0, 4);
for(int i=1; i<= 4; ++i)
combination(t1, 0, i, new ArrayList<Character>());
public static void permutation(char[] data, int begin, int end) {
if(begin == end -1) {
System.out.println(data);
return ;
}
for(int i=begin; i<end; ++i) {
swap(data, begin, i);
permutation(data, begin+1, end);
swap(data, begin, i);
}
}
public static void combination(char[] data, int begin, int m, ArrayList<Character> res) {
if(m == 0) {
System.out.println(res);
return;
}
if(begin == data.length) {
return;
}
res.add(data[begin]);
combination(data, begin+1, m-1, res);
res.remove(res.size()-1);
combination(data, begin+1, m, res);
}