{menu}{mirror} |
|
Presented below is the C++ algorithm which answered Dr. Milito's question proposed sometime after the Fall of 1986. Using a target array of size N, two distinct variables (J, I) can be accessed for all head transpositions as well as two distinct variables (Q, R) for all tail transpositions. Given two target arrays called h[N], t[N] and the Meta-permutation object m(N), SWAP(h[m[J]], h[m[I]]) is valid for all head combinations whereas SWAP(t[m[Q], t[m[R]]) is valid for all tail combinations provided that all SWAP calls are followed by a single m.next() call to calculate four new index values.
Using a nested while loop in the countdown QuickPerm algorithm clearly lead to the development of a Meta-permutation class (below). In contrast, replacing the nested while loop with a conditional if-else statement as described in the counting QuickPerm algorithm causes the Meta-permutation class to "skip" index calculations due to an obvious dependency on the outer loop. Although this conditional substitution can be made regardless of the counting process utilized, the Meta-Permutation Class precludes such a substitution in order to return valid indices.
Example_05 efficiently combines the four previous examples by utilizing a single Meta-Permutation Class aptly named MetaPerm. Here's the Meta-Permutation Class written in C++ for your review:
|
|