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