字符串全排列
#include<iostream> using namespace std; #include<assert.h> void Permutation(char* pStr, char* pBegin) { //assert(pStr && pBegin); 这个可以替换下面的if if(pStr == NULL || pBegin == NULL) { return; } if(*pBegin == '\0') printf("%s\n",pStr); else { for(char* pCh = pBegin; *pCh != '\0'; pCh++) { swap(*pBegin,*pCh); Permutation(pStr, pBegin+1); swap(*pBegin,*pCh); } } } int main(void) { char str[] = "abc"; Permutation(str,str); return 0; }