C++ STL 排列 next_permutation prev_permutation

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

using namespace std;

int main()
{
  vector<int> vec1;
  for (int k=0;k<5;k++)
  {
    vec1.push_back(rand());
  }

  vector<int>::iterator vec_iter1;
  for (vec_iter1 = vec1.begin();vec_iter1 != vec1.end();++vec_iter1)
  {
    cout << *vec_iter1 << " ";
  }
  cout << endl;
  cout << "----------------------------------" << endl;

  
  while (next_permutation(vec1.begin(),vec1.end()))
  {
    for (vector<int>::iterator vec_iter2 = vec1.begin(); vec_iter2 != vec1.end(); ++vec_iter2)
    {
      cout << *vec_iter2 << " ";
    }
    cout << endl;
    cout << "----------------------------------" << endl;
  }

 

 


  system("pause");
  return 0;
}

========================================

41 18467 6334 26500 19169
----------------------------------
41 18467 19169 6334 26500
----------------------------------
41 18467 19169 26500 6334
----------------------------------
41 18467 26500 6334 19169
----------------------------------
41 18467 26500 19169 6334
----------------------------------
41 19169 6334 18467 26500
----------------------------------
41 19169 6334 26500 18467
----------------------------------
41 19169 18467 6334 26500
----------------------------------
41 19169 18467 26500 6334
----------------------------------
41 19169 26500 6334 18467
----------------------------------
41 19169 26500 18467 6334
----------------------------------
41 26500 6334 18467 19169
----------------------------------
41 26500 6334 19169 18467
----------------------------------
41 26500 18467 6334 19169
----------------------------------
41 26500 18467 19169 6334
----------------------------------
41 26500 19169 6334 18467
----------------------------------
41 26500 19169 18467 6334
----------------------------------
6334 41 18467 19169 26500
----------------------------------
6334 41 18467 26500 19169
----------------------------------
6334 41 19169 18467 26500
----------------------------------
6334 41 19169 26500 18467
----------------------------------
6334 41 26500 18467 19169
----------------------------------
6334 41 26500 19169 18467
----------------------------------
6334 18467 41 19169 26500
----------------------------------
6334 18467 41 26500 19169
----------------------------------
6334 18467 19169 41 26500
----------------------------------
6334 18467 19169 26500 41
----------------------------------
6334 18467 26500 41 19169
----------------------------------
6334 18467 26500 19169 41
----------------------------------
6334 19169 41 18467 26500
----------------------------------
6334 19169 41 26500 18467
----------------------------------
6334 19169 18467 41 26500
----------------------------------
6334 19169 18467 26500 41
----------------------------------
6334 19169 26500 41 18467
----------------------------------
6334 19169 26500 18467 41
----------------------------------
6334 26500 41 18467 19169
----------------------------------
6334 26500 41 19169 18467
----------------------------------
6334 26500 18467 41 19169
----------------------------------
6334 26500 18467 19169 41
----------------------------------
6334 26500 19169 41 18467
----------------------------------
6334 26500 19169 18467 41
----------------------------------
18467 41 6334 19169 26500
----------------------------------
18467 41 6334 26500 19169
----------------------------------
18467 41 19169 6334 26500
----------------------------------
18467 41 19169 26500 6334
----------------------------------
18467 41 26500 6334 19169
----------------------------------
18467 41 26500 19169 6334
----------------------------------
18467 6334 41 19169 26500
----------------------------------
18467 6334 41 26500 19169
----------------------------------
18467 6334 19169 41 26500
----------------------------------
18467 6334 19169 26500 41
----------------------------------
18467 6334 26500 41 19169
----------------------------------
18467 6334 26500 19169 41
----------------------------------
18467 19169 41 6334 26500
----------------------------------
18467 19169 41 26500 6334
----------------------------------
18467 19169 6334 41 26500
----------------------------------
18467 19169 6334 26500 41
----------------------------------
18467 19169 26500 41 6334
----------------------------------
18467 19169 26500 6334 41
----------------------------------
18467 26500 41 6334 19169
----------------------------------
18467 26500 41 19169 6334
----------------------------------
18467 26500 6334 41 19169
----------------------------------
18467 26500 6334 19169 41
----------------------------------
18467 26500 19169 41 6334
----------------------------------
18467 26500 19169 6334 41
----------------------------------
19169 41 6334 18467 26500
----------------------------------
19169 41 6334 26500 18467
----------------------------------
19169 41 18467 6334 26500
----------------------------------
19169 41 18467 26500 6334
----------------------------------
19169 41 26500 6334 18467
----------------------------------
19169 41 26500 18467 6334
----------------------------------
19169 6334 41 18467 26500
----------------------------------
19169 6334 41 26500 18467
----------------------------------
19169 6334 18467 41 26500
----------------------------------
19169 6334 18467 26500 41
----------------------------------
19169 6334 26500 41 18467
----------------------------------
19169 6334 26500 18467 41
----------------------------------
19169 18467 41 6334 26500
----------------------------------
19169 18467 41 26500 6334
----------------------------------
19169 18467 6334 41 26500
----------------------------------
19169 18467 6334 26500 41
----------------------------------
19169 18467 26500 41 6334
----------------------------------
19169 18467 26500 6334 41
----------------------------------
19169 26500 41 6334 18467
----------------------------------
19169 26500 41 18467 6334
----------------------------------
19169 26500 6334 41 18467
----------------------------------
19169 26500 6334 18467 41
----------------------------------
19169 26500 18467 41 6334
----------------------------------
19169 26500 18467 6334 41
----------------------------------
26500 41 6334 18467 19169
----------------------------------
26500 41 6334 19169 18467
----------------------------------
26500 41 18467 6334 19169
----------------------------------
26500 41 18467 19169 6334
----------------------------------
26500 41 19169 6334 18467
----------------------------------
26500 41 19169 18467 6334
----------------------------------
26500 6334 41 18467 19169
----------------------------------
26500 6334 41 19169 18467
----------------------------------
26500 6334 18467 41 19169
----------------------------------
26500 6334 18467 19169 41
----------------------------------
26500 6334 19169 41 18467
----------------------------------
26500 6334 19169 18467 41
----------------------------------
26500 18467 41 6334 19169
----------------------------------
26500 18467 41 19169 6334
----------------------------------
26500 18467 6334 41 19169
----------------------------------
26500 18467 6334 19169 41
----------------------------------
26500 18467 19169 41 6334
----------------------------------
26500 18467 19169 6334 41
----------------------------------
26500 19169 41 6334 18467
----------------------------------
26500 19169 41 18467 6334
----------------------------------
26500 19169 6334 41 18467
----------------------------------
26500 19169 6334 18467 41
----------------------------------
26500 19169 18467 41 6334
----------------------------------
26500 19169 18467 6334 41
----------------------------------
请按任意键继续. . .

posted @ 2019-06-12 20:03  西北逍遥  阅读(228)  评论(0编辑  收藏  举报