next_permutation函数用法:用来生成下一个排列
// 程序7-2-4.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<algorithm>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
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;
}