Ideas
The following is a concrete example of the implementation of this idea, such as the realization of 123 of the full array of combinations.
Requires 123 of the full arrangement, can be divided into the following situations:
Case 1: Full arrangement of the No. 0 place for 1+23
Case 2: Full arrangement of the No. 0 place for 2+13
Case 3: Full arrangement of the No. 0 place for 3+32
The above situation is implemented in code as follows:
//Situation 1//In order to be consistent with the following, plus Swap (list[0],list[0]);PermList,1,2);//In order to be consistent with the following, plus Swap (list[0],list[0]);//Situation 2SwapList[0],List[1]);p ERM (List,1,2); Swap (List[0],List[1]);//Situation 3SwapList[0],List[2]);p ERM (List,1,2); Swap (List[0],List[2]);
These 3 situations can be replaced by bad:
for(int i=0;i<=2;i++){ swap(list[0],list[i]); perm(list,1,2); swap(list[0],list[i]);}
"Full alignment implementation code one"
#include <iostream>using namespace STD;voidPermChar List[],intKintm);voidPermChar List[],intKintm) {if(k==m) { for(intj=0; j<=m;j++) {cout<<List[j]; }cout<<endl; }Else{ for(inti=k;i<=m;i++) {STD:: Swap (List[K],List[i]); PermList, K +1, m);STD:: Swap (List[K],List[i]); } }}intMain () {Chara[]="123"; Perm (A,0,2); System"Pause");return 0;}
Recursive implementation of the full array (i)