Recursive implementation of the full array (i)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.