Friday, 24 November 2017

C++ Program to Implement Prev_Permutation in STL


Code:

#include     iostream
#include     algorithm
using namespace std;
void display(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        cout<
    }
    cout<
}
int main ()
{
    int num, i;
    cout<<"Enter number of elements to be inserted: ";
    cin>>num;
    int myints[num];
    for (i = 0; i < num; i++)
    {
        cout<<"Enter "<
        cin>>myints[i];
    }
    sort (myints, myints + num);
    reverse (myints, myints + num);
    cout << "The "<
    cout<
    do
    {
        display(myints, num);
    }
    while (prev_permutation(myints, myints + num));
    return 0;
}


Output:

Enter number of elements to be inserted: 3
Enter 1 element: 3
Enter 2 element: 2
Enter 3 element: 1
The 3! possible permutations with 3 elements: 
3  2  1  
3  1  2  
2  3  1  
2  1  3  
1  3  2  
1  2  3  


------------------
(program exited with code: 0)
Press return to continue



More C++ Programs:
















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...