The examples rely on this definition:
permu_arr_0<13> const q {4, 8, 6, 5, 12, 3, 7, 11, 1, 2, 10, 0, 9};
|
void reverse_position // zero-based
(int const lo = 0, int const hi = -1);
void reverse_position // one-based
(int const lo = 1, int const hi = 0);
- lo is the first position of the reversal region;
- hi is one past the last position of the reversal region.
|
void reverse_value // zero-based
(int const lo = 0, int const hi = -1);
void reverse_value // one-based
(int const lo = 1, int const hi = 0);
- lo is the lowest value to reverse;
- hi is one more than the highest value to reverse.
|
Given these statements:
permu_arr_0<13> p {q};
p.reverse_position (3, 8);
what happens is:
- the elements at positions 3 and 7 are exchanged;
- the elements at positions 4 and 6 are exchanged.
Unnecessary is the exchange of the element at position 5 with itself.
table 1 — zero-based reverse_position
|
---|
position:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
| original:
| 4 | 8 | 6 | 5 | 12 | 3 | 7 | 11 | 1 | 2 | 10 | 0 | 9
| (3, 8):
| 4 | 8 | 6 | 11 | 7 | 3 | 12 | 5 | 1 | 2 | 10 | 0 | 9
|
| Given these statements:
permu_arr_0<13> p {q};
p.reverse_value (3, 8);
what happens is:
- elements 3 and 7 are exchanged;
- elements 4 and 6 are exchanged.
Unnecessary is the exchange of element 5 with itself.
table 2 — zero-based reverse_value
|
---|
position:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
| original:
| 4 | 8 | 6 | 5 | 12 | 3 | 7 | 11 | 1 | 2 | 10 | 0 | 9
| (3, 8):
| 6 | 8 | 4 | 5 | 12 | 7 | 3 | 11 | 1 | 2 | 10 | 0 | 9
|
|
↑ equivalent ↓
| ↑ equivalent ↓
|
Given these statements:
permu_arr_1<13> p {q};
p.reverse_position (4, 9);
what happens is:
- the elements at positions 4 and 8 are exchanged;
- the elements at positions 5 and 7 are exchanged.
Unnecessary is the exchange of the element at position 6 with itself.
table 3 — one-based reverse_position
|
---|
position:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
| original:
| 5 | 9 | 7 | 6 | 13 | 4 | 8 | 12 | 2 | 3 | 11 | 1 | 10
| (4, 9):
| 5 | 9 | 7 | 12 | 8 | 4 | 13 | 6 | 2 | 3 | 11 | 1 | 10
|
| Given these statements:
permu_arr_1<13> p {q};
p.reverse_value (4, 9);
what happens is:
- elements 4 and 8 are exchanged;
- elements 5 and 7 are exchanged.
Unnecessary is the exchange of element 6 with itself.
table 4 — one-based reverse_value
|
---|
position:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
| original:
| 5 | 9 | 7 | 6 | 13 | 4 | 8 | 12 | 2 | 3 | 11 | 1 | 10
| (4, 9):
| 7 | 9 | 5 | 6 | 13 | 8 | 4 | 12 | 2 | 3 | 11 | 1 | 10
|
|
permu_vec_0 and permu_vec_1 work the same way.
|