案例代码:
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,p[10];
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&p[i]);
sort(p,p+n); //排序,得到p的最小排列
do
{
for(int i=0;i<n;i++) printf("%d ",p[i]);//输出排列p
printf("\n");
}while(next_permutation(p,p+n));//求下一个排列
return 0;
}
//需要注意的是上述代码同样适用于可重集
这与https://blog.csdn.net/weixin_42373330/article/details/82465363的代码功能相似