Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83 based; site hou2f.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!hou2f!vifl From: vifl@hou2f.UUCP (M.MEKETON) Newsgroups: net.micro.pc Subject: Re: Permutations Message-ID: <290@hou2f.UUCP> Date: Mon, 23-Jul-84 14:12:13 EDT Article-I.D.: hou2f.290 Posted: Mon Jul 23 14:12:13 1984 Date-Received: Tue, 24-Jul-84 04:11:28 EDT Organization: AT&T Bell Labs, Holmdel NJ Lines: 34 Here is an implementation of the permutation algorithm in C, without using recursion. It takes an integer, n, on the command line and creates all the permutations of {1,2,..,n}. Translations to PASCAL, FORTRAN, etc., are straigtforward. #define MAX_N 10 main(argc,argv) int argc; char *argv[]; { int N, x[MAX_N+2], i, j, y[MAX_N+1]; sscanf(argv[1],"%d",&N); for (i=1;i<=N;x[i++]=1); while (x[N+1] < 1) { for (i=1;i<=N;y[i++]=i); for (i=N;i>=2;i--) { printf("%d ",y[x[i]]); for (j=x[i];j i) {x[i] = 1; x[++i]++;} } } Marc S. Meketon ATT-BL Holmdel, NJ