Next permutation

syntax of next_permutation()

@janmejai20singh hey ,here is syntax:
bool next_permutation (BidirectionalIterator first,
BidirectionalIterator last);
Parameters:
first, last : Bidirectional iterators to the initial
and final positions of the sequence. The range
used is [first, last), which contains all the elements
between first and last, including the element pointed
by first but not the element pointed by last.

return value:
true : if the function could rearrange
the object as a lexicographicaly greater permutation.
Otherwise, the function returns false to indicate that
the arrangementis not greater than the previous,
but the lowest possible (sorted in ascending order).
eg.
#include <algorithm>

#include <iostream>

using namespace std;

int main()

{

int arr[] = { 1, 2, 3 };

sort(arr, arr + 3);

cout << "The 3! possible permutations with 3 elements:\n" ;

do {

cout << arr[0] << " " << arr[1] << " " << arr[2] << "\n" ;

} while (next_permutation(arr, arr + 3));

cout << "After loop: " << arr[0] << ' '

<< arr[1] << ' ' << arr[2] << '\n' ;

return 0;

}
The 3! possible permutations with 3 elements:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
After loop: 1 2 3

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.