包含在c++<algorithm>库中的next_permutation(arr,arr+n)函数可以实现arr中元素的全排列
但是要求arr中元素事先已经按字典序排列好
具体使用方法如下:
#include#include 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< <<" "; } cout<