The following program can demonstrates you that how to use the next_permutation() function in the programming of the C++ language while doing the coding using the next_permutation() function as shown below :
Code:
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
int min[] = {1,2,3};
cout << "The 3! possible permutations with 3 elements:\n";
sort (min,min+3);
do
{
cout << min[0] << " " << min[1] << " " << min[2] << endl;
} while ( next_permutation (min,min+3) );
return 0;
}
Output:
Code:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Bookmarks