自己重写的下一个排列函数
#include <iostream>
#include <algorithm>
using namespace std;
#define N 100000
int p[N];
int _next_permutation(int *first, int *last)
{
int *p,*q;
for (p = last; p != first; p--)
{
if (*p > *(p - 1))
{
int *a = p;
for (q = p; q != last; q++)
{
if (*q > *(p - 1) && *q < *a)
{
a = q;
}
}
int temp = *a;
*a = *(p - 1);
*(p - 1) = temp;
sort(p, last);
return 1;
}
}
return 0;
}
int main()
{
int n,i;
cin >> n;
for (i = 0; i < n; i++)
cin >> p[i];
sort(p, p + n);
do
{
for (i = 0; i < n; i++)
cout << p[i];
cout << endl;
} while (_next_permutation(p, p + n));
return 0;
}