Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!hubcap!grimlok From: grimlok@hubcap.clemson.edu (Mike Percy) Newsgroups: comp.lang.c Subject: need good permutaion generator in C Message-ID: <11039@hubcap.clemson.edu> Date: 19 Oct 90 15:15:37 GMT Organization: Clemson University, Clemson, SC Lines: 27 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@hubcap.clemson.edu ISD, Clemson University mspercy@clemson.BITNET (803)656-3780 mspercy@clemson.clemson.edu