I have the following program using function next_permutation() and the output:
8 int main ()
9 {
10 int myints[] = {1, 2, 3};
11
12 cout << "Before : " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << endl;
13
14 do {
15 cout << "loop : ";
16 cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << endl;
17 } while ( next_permutation(myints, myints + 3) );
18
19 cout << "After : " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << endl;
20
21 return 0;
22 }
$ ./a.out
Before : 1 2 3
loop : 1 2 3
loop : 1 3 2
loop : 2 1 3
loop : 2 3 1
loop : 3 1 2
loop : 3 2 1
After : 1 2 3
I am expecting line 19 to output "3 2 1" per the description of next_permutation() (http://www.cplusplus.com/reference/algorithm/next_permutation/, which has same sample program), but as can be seen the output is "1 2 3". Can someone please help me understand.
Thank you, Ahmed.