Title: Enter a string to print out all the permutations of the characters in the string. For example, the input string ABC prints out all the string ABC,ACB,BAC,BCA,CAB,CBA that can be arranged by the character A,b,c.
Analysis: First of all the characters that may appear in the first position, that is, the first character and all subsequent characters are exchanged. In the second step, a character is fixed, and all the characters in the back are arranged. The following characters can still be used in this way. is obviously a recursive process. The implementation is as follows:
Void permutation (CHAR* PSTR) { if (pstr==null) return; permutation ( PSTR,PSTR);} Void permutation (Char* pstr,char* pbegin) { if (*pBegin== ') { printf ("%s\n", pStr); } else { for (char* pch=pbegin;*pch!= ' + '; ++pch) { char temp=*pCh; *pCh=*pBegin; *pBegin=temp; permutation (pstr,pbegin+1); temp=*pch; *pch=*pbegin; *pBegin=temp; } }}
The solution to the problem is: all combinations of characters, eight Queen questions, and so on.
This article from "Fairy Road thousands of dust Dream" blog, please be sure to keep this source http://secondscript.blog.51cto.com/9370042/1585597
Arrangement of strings