字符串全排列
程序员文章站
2023-10-06 11:41:46
void AllSortCore(char *str,int begin,int end); void AllSort(char *str) { if(str == NULL) return ; int n = strlen(str); AllSortCore(str,0,n-1); } void ... ......
void allsortcore(char *str,int begin,int end); void allsort(char *str) { if(str == null) return ; int n = strlen(str); allsortcore(str,0,n-1); } void allsortcore(char *str,int begin,int end) { if(end <=1) return ; if(begin == end) { cout<<str<<endl; } for(int j = begin;j<=end;++j) { swap(str[j],str[begin]); allsortcore(str,begin+1,end); swap(str[j],str[begin]); } }