Sorry not to give more info. The code I can come up with so far is:
function permutations(N) {
let c = 1;
loop: while (true) {
if (N > 2) permutations(N - 1);
if (c < N) {
swap(P, P[B[N, c]], P[N]);
c = c + 1;
continue loop;
}
break loop;
}
}
But I never was very comfortable with the old style of pseudocode. And yes, P
is the array to permute, and B
is an array which Sedgewick fills with magic indices.