1. 程式人生 > >字符串全排列

字符串全排列

null int urn end core bsp 字符串全排列 color rtc

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]); } }

字符串全排列