need good permutaion generator in C

Mike Percy grimlok at hubcap.clemson.edu
Sat Oct 20 01:15:37 AEST 1990


I'm looking for an iterative (not recursive like the ones I already
know) permutation routine -- to wit:
 
int T[] = { 1, 2, 3}   
 
for(i = 0; i < n!; i++)
{
  /* make permutation(i) of T */
  /* use permutation(i) of T */
}

the permutations of T are 
1 2 3 
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
 
I see a swap() coming into play, but I can't quite get it right. 
Also, I'm not picky about what order the permutations come out in,
just that each be generated exactly once.

"I don't know about your brain, but mine is really...bossy."
Mike Percy                    grimlok at hubcap.clemson.edu
ISD, Clemson University       mspercy at clemson.BITNET
(803)656-3780                 mspercy at clemson.clemson.edu



More information about the Comp.lang.c mailing list