字符串的全排列程序

来源:互联网 发布:nba2kol软件 编辑:程序博客网 时间:2024/06/05 07:08
#include <iostream>#include <cstring>using namespace std;void swap (char *str, int i, int j){char tmp = str[i];str[i] = str[j];str[j] = tmp;}void fullarrange (char *str, int beg, int nlen){static int cnt = 0;if ( beg < nlen-1){for (int i=beg; i<nlen; i++){swap(str, beg, i);fullarrange(str, beg+1, nlen);swap(str, beg, i);}}else{cout<<++cnt<<": "<<str<<endl;}}int main (){char str[16]="abcde";int nlen = strlen(str);fullarrange(str, 0, nlen);return 0;}

原创粉丝点击