|
#include <stdio.h>
void main ()
{
const int N = 4;
unsigned int s [N], d [N], e [N];
int p, q, r, i, k;
s [0] = s [1] = 1;
for (i = 2; i <N; ++ i)
{
s [i] = d [i] = i;
e [i] =-1;
}
bool loop = false;
do {
q = 0;
lop = false;
for (i = 1; i <N; ++ i) printf ("% d", s [i]);
printf ("\n");
for (k = N-1; k> = 2;-k)
{
d [k] = d [k] + e [k];
p = d [k];
if (p == k)
e [k] =-1;
else if (p == 0)
{
e [k] = 1; ++ q;
}
else
{
p + = q; r = s [p]; s [p] = s [p + 1]; s [p + 1] = r;
loop = true;
}
} while (loop);
}
} |
|