包含在c++<algorithm>库中的next_permutation(arr,arr+n)函数可以实现arr中元素的全排列

但是要求arr中元素事先已经按字典序排列好

具体使用方法如下:

#include <iostream>
#include <algorithm>

using namespace std;

int arr[5]={1,3,2,3,4};

int main()
{
    sort(arr,arr+5);
    while(next_permutation(arr,arr+5))
    {
        for(int i=0;i<5;i++)
        {
            cout<<arr[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

 

相关文章:

  • 2021-05-11
  • 2021-12-26
  • 2022-02-11
  • 2021-08-24
  • 2021-08-24
  • 2022-12-23
  • 2021-08-30
  • 2021-06-27
猜你喜欢
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
相关资源
相似解决方案