// test_permute.cpp // make use of template permute in algorithm standard template library #include #include #include #include using namespace std; // TEMPLATE FUNCTION next_permutation //template inline // bool next_permutation(_BI _F, _BI _L) // _BI stands for bidirectional iterator // {_BI _I = _L; // _F stands for first e.g. v.begin() // if (_F == _L || _F == --_I) // _L stands for last e.g. v.end() // return (false); // for (; ; ) // {_BI _Ip = _I; // if (*--_I < *_Ip) // {_BI _J = _L; // for (; !(*_I < *--_J); ) // ; // iter_swap(_I, _J); // reverse(_Ip, _L); // return (true); } // if (_I == _F) // {reverse(_F, _L); // return (false); }}} typedef list arr; typedef vector arr4; int main(int argc, char *argv[]) { arr a; arr::iterator p; arr4 aa(4); cout << "test_permute starting" << endl; a.push_back(1); a.push_back(2); a.push_back(3); a.push_back(4); cout << "Initial values of a:"; p = a.begin(); while(p != a.end()) { cout << *p; p++; } cout << endl; while(next_permutation(a.begin(),a.end())) { cout << "a= "; p = a.begin(); while(p != a.end()) { cout << *p; p++; } cout << endl; } aa[0]=1; aa[1]=2; aa[2]=3; aa[3]=4; cout << "Initial values of aa" << aa[0] << aa[1] << aa[2] << aa[3] << endl; while(next_permutation(aa.begin(),aa.end())) { cout << "aa=" << aa[0] << aa[1] << aa[2] << aa[3] << endl; } cout << "test_permute finished" << endl; return 0; }