打印字符串的全排列

#include<iostream>
using namespace std;
void permutation(char* str, char* begin){
if (*begin == '\0')
cout << str<<endl;
else{
for (char* ch = begin; *ch != '\0'; ch++){
char tmp = *ch;
*ch = *begin;
*begin = tmp;
permutation(str, begin + 1);
*begin = *ch;
*ch = tmp;
}
}
}
int main(){
char str[] = "abc";
permutation(str, str);
}

猜你喜欢

转载自blog.csdn.net/tiger1334/article/details/48750829