All permutations of ABC by use of prev_permutation() : next_permutation « STL Algorithms Helper « C++ Tutorial






#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  vector<char> v;
  unsigned i;

  for(i=0; i<3; i++) v.push_back('A'+i);

  prev_permutation(v.begin(), v.end());
  
  do {
    for(i=0; i<v.size(); i++)
      cout << v[i] << endl;
  } while(prev_permutation(v.begin(), v.end()));

  return 0;
}








32.13.next_permutation
32.13.1.Illustrating the generic next_permutation algorithms
32.13.2.next_permutation() and prev_permutation().
32.13.3.All permutations of ABC by use of prev_permutation()
32.13.4.All permutations of ABC by use of next_permutation()
32.13.5.Use next_permutation to permute elements until they are sorted