template <class BidirIterator> bool prev_permutation( BidirIterator xFirst, BidirIterator xLast );
#include <algorithm>
template <class BidirIterator, class BinaryPred> bool prev_permutation( BidirIterator xFirst, BidirIterator xLast, BinaryPred xComp );
#include <iostream>
#include <deque>
#include <algorithm>
int main()
{
using namespace std;
// Create a deque instance
deque<int> qD;
for (int i = 1; i <= 3; ++i) {
qD.push_back(i);
}
// Call once to get the last permutation
prev_permutation(qD.begin(), qD.end());
deque<int>::iterator qIter;
// Output the permutation
cout << "Initial Perm: ";
for (qIter = qD.begin(); qIter != qD.end(); ++qIter) {
cout << *qIter;
}
cout << endl;
// Run through each permutation backwards
bool bHasNext = true;
while (bHasNext) {
bHasNext = prev_permutation(qD.begin(), qD.end());
cout << "Permutated : ";
for (qIter = qD.begin(); qIter != qD.end(); ++qIter) {
cout << *qIter;
}
cout << endl;
}
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.