關于字符串的全排列的算法
其中IsSwap()是用來剔除會導致重復的排列的情況的!
void Permutation(char* pStr){ if(pStr==NULL) return; PermutationCore(pStr,pStr);}bool IsSwap(char* Begin,char*End ){ while(Begin!=End) { if(*Begin==*End) return false; Begin++; } return true;}void PermutationCore(char* pStr,char* pBegin){ if(*pBegin=='/0') { PRintf("%s/n",pStr); } else { for(char* pCh=pBegin;*pCh!='/0';++pCh) { if(IsSwap(pBegin,pCh)) { Swap(pCh,pBegin); PermutationCore(pStr,pBegin+1); Swap(pCh,pBegin); } } }}
新聞熱點
疑難解答