#include <iostream>
using namespace std;
void print(char* str, int length);
void permutation(char* str, int begin, int length);
void permutation(char* str, int length) {
if (str == NULL || length <= 0)
return;
permutation(str, 0, length);
}
void permutation(char* str, int begin, int length) {
if (begin == length - 1) {
print(str,length);
}
char t;
for (int i = begin; i < length; i++) {
t = str[begin];
str[begin] = str[i];
str[i] = t;
permutation(str, begin + 1, length);
}
}
void print(char* str, int length) {
for (int i = 0; i < length; i++) {
cout << str[i];
}
cout << endl;
}
int main() {
char string1[] = "";
char string2[] = "a";
char string3[] = "ab";
char string4[] = "abc";
permutation(string1,0);
permutation(string2,1);
permutation(string3,2);
permutation(string4,3);
return 0;
}
剑指Offer-28-字符串排列
最新推荐文章于 2020-03-25 22:04:30 发布