Home page.


This page contrasts the reverse_position and reverse_value functions. They reverse values within a permutation.

Function reverse_position is a wrapper for std::reverse.

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: 0123456789101112
original: 4865123711121009
(3, 8): 4861173125121009

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: 0123456789101112
original: 4865123711121009
(3, 8): 6845127311121009

equivalentequivalent
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: 12345678910111213
original: 59761348122311110
(4, 9): 59712841362311110

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: 12345678910111213
original: 59761348122311110
(4, 9): 79561384122311110

permu_vec_0 and permu_vec_1 work the same way.