直接看样例
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int arr[] = {3, 2, 1};
cout << "用prev_permutation对3 2 1的全排列" << endl;
do
{
cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << '\n';
} while (prev_permutation(arr, arr + 3));
int arr1[] = {1, 2, 3};
cout << "用next_permutation对1 2 3的全排列" << endl;
do
{
cout << arr1[0] << ' ' << arr1[1] << ' ' << arr1[2] << '\n';
} while (next_permutation(arr1, arr1 + 3));
return 0;
}
运行输出
用prev_permutation对3 2 1的全排列
3 2 1
3 1 2
2 3 1
2 1 3
1 3 2
1 2 3
用next_permutation对1 2 3的全排列
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1