``````// NOTICE: Copyright 1991-2010, Phillip Paul Fuchs #define N 12 // number of elements to permute. Let N > 2 void example_04(void) { const unsigned int ax = N - 1; // constant index ceiling (a[N] length) unsigned int a[N], p[N]; // target array and index control array  register unsigned int i, j, tmp; // index variables and tmp for swap for(i = 0; i < N; i++) // initialize arrays; a[N] can be any type { a[i] = N - i; // a[i] value is arbitrary and not revealed p[i] = N - i; } //display(a); // remove comment to display array a[] i = ax; // setup first swap point to be ax while (i > 0) { p[i]--; // decrease index "weight" for i by one i--; // i must be less then j (i < j) j = ax; // reset j to ax do // reverse target array from i to j { tmp = a[j]; // swap(a[i], a[j]) a[j] = a[i]; a[i] = tmp; j--; // decrement j by 1 i++; // increment i by 1 } while (j > i); //display(a); // remove comment to display target array a[] i = ax; // reset index i to ax (assumed) while (!p[i]) // while (p[i] == 0) { p[i] = N - i; // reset p[i] zero value i--; // set new index value for i (decrease by one) } // while (!p[i]) } // while (i > 0) } // example_04() ``````
 ``````// NOTICE: Copyright 1991-2010, Phillip Paul Fuchs                          void display(unsigned int *a) { for(unsigned int x = 0; x < N; x++) printf("%d ",a[x]); printf("\n"); getch(); // press any key to continue... } // display() ``````