/* permute.c */ /* CAUTION: N factorial permutations is a bunch for N > 9 * The precise definition of a bunch is 3,628,800 up * 7! = 5,040 8! = 40,320 9! = 362,880 * * INPUT: vector - input and output vector that is permuted * This must be set up befor the first call * and then used as the next permutation on * each return * * INIT: permuters[0] != 0 typ = n+1 * * OUTPUT: vector - the next permuted vector * if_last = FALSE if more permutations to be returned * = TRUE if the last permutation is being * returned (done) */ #define TRUE 1 #define FALSE 0 int permute(int n, int vector[], int permuters[]) { int i,j,k,t; int if_last = FALSE; if(n <= 1)return if_last=TRUE; if(permuters[0] != 0){ /* Initialization ( user must set up vector before first call */ for(i=0;i0){ k--; if(permuters[k] != 0){ return if_last; } } if_last = TRUE; } } return if_last; } /* end permute.c */ int permuted(int n, double vector[], int permuters[]) { int i,j,k; double t; int if_last = FALSE; if(n <= 1)return if_last=TRUE; if(permuters[0] != 0){ /* Initialization ( user must set up vector before first call */ for(i=0;i0){ k--; if(permuters[k] != 0){ return if_last; } } if_last = TRUE; } } return if_last; } /* end permuted */ /* end permute.c */