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<INT>:: 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<INT>:: 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 ()