The output array is fully arranged

Source: Internet
Author: User

    • has not been realized before, today understand
#include <iostream>#include<iterator>using namespacestd;//The output array is fully arranged//Algorithm Ideas://(1) The full arrangement of n elements = (full permutation of n-1 elements) + (another element as prefix);//(2) Export: If only one element is fully arranged, then the output array is finished;//(3) continue to put each element as the first element, and then the element as a prefix, and the rest of the elements continue to be fully arranged, wait until the exit, export, you need to restore the array;voidPermintList[],intKintm) {    if(k = =m) {copy (list, list+ M, ostream_iterator<int> (cout," ")); cout<<Endl; return; }     for(inti = k; I < m; i++)//For the first time I changed myself{swap (list[k], list[i]); Perm (list, K+1, M);    Swap (List[k], list[i]); }}intMain () {intList[] = {1,2,3 }; Perm (List,0,sizeof(List)/sizeof(int)); return 0;}

The output array is fully arranged

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.