C++ 全排列函数 next_permutation与prev_permutation
C++ STL中提供了next_permutation与prev_permutation可以获取数字或者是字符的全排列,其中next_permutation提供升序、prev_permutation提供降序。
1.next_permutation(first,last)
说明:对[first,last)区间进行排列,第一次输出当前的排列顺序,例如:1234,第二次输出比第一次大的下一种排列,则为1243(若为数组,则通过数字比较来判断大小,若为字符串,则通过ASCII码来比较大小)。
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[100];
int n=0,i;
while(cin>>a[n])
n++;
sort(a,a+n);
//输出升序的全排列则应将最