Stl_ Algorithm (17) _ Permutation combination next_permutation () perv_permutation ()

Source: Internet
Author: User

Next_permutation ()

Prev_permutation ()

#include <iostream> #include <algorithm> #include <vector>//You must first sort the using namespace before starting the arrangement Std;int Main () {vector<int> ivec;ivec.push_back (1); Ivec.push_back (2); Ivec.push_back (3); for (VECTOR&LT;INT&GT;:: Iterator iter = Ivec.begin (); Iter! = Ivec.end (); iter++) cout << *iter << "cout << endl;//next permutation combination the algorithm returns a bool if the return value is True the next permutation combination is also available, but if the arrangement for the fals description is sorted Finished Next_permutation (Ivec.begin (), Ivec.end ()); for (Vector<int>::iterator iter = Ivec.begin (); ITER! = Ivec.end () ; iter++) cout << *iter << "cout << endl;while (Next_permutation (Ivec.begin (), Ivec.end ())) {for ( Vector<int>::iterator iter = Ivec.begin (); Iter! = Ivec.end (); iter++) cout << *iter << "cout << Endl;} cout << Endl << endl;cout << endl << endl;cout << endl << endl;vector<int> ivec2 ; Ivec2.push_back (3); Ivec2.push_back (2); Ivec2.push_back (1); for (Vector<int>::iterator iter = Ivec2.begin (); Iter! = IVec2.end (); iter++) cout << *iter; '; cout << ENDL;//IVEC2 itself is a reverse while (Prev_permutation (Ivec2.begin (), Ivec2.end ())}) {for (VECTOR&LT;INT&GT;:: Iterator iter = Ivec2.begin (); Iter! = Ivec2.end (); iter++) cout << *iter; "; cout << Endl;} System ("pause"); return 0;}




Stl_ Algorithm (17) _ Permutation combination next_permutation () perv_permutation ()

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.