// Created by Alex Kontorovich & John F. Nash Jr. 6/11/2002 void reverse_sort(double **vect) // sorts elements in vect of size coalitions from biggest to smallest { double temp; int i,j,found,low,mid,high; for (i=1;i=(*vect)[0]) mid=0; else if (temp<=(*vect)[i-1]) mid=i; else { low=0; high=i-1; mid=(low+high)/2; found=0; while (!found) { if (temp==(*vect)[mid]) // if we're equal, done, found it found=1; else if (temp>(*vect)[mid]) // if location is bigger { if (temp<(*vect)[mid-1]) // found right place found=1; else // close in bars { high=mid; mid=(low+high)/2; } } else // temp < location, bump up low { low=mid; mid=(low+high)/2; if (high-low<2) mid+=found=1; // tricky way of setting found=1 and mid++ in one line } if (high==low) found=1; } } // mid now contains correct place for (j=i-1;j>=mid;j--) (*vect)[j+1]=(*vect)[j]; (*vect)[mid]=temp; } return; } int less_than(double *v1, double *v2) // returns true if v1 != v2, and v1 is lexicographically smaller than v2. Vectors of size coalitions { int i=0; while ((iv2[i]) return 0; // v1 not smaller than v2 return 1; // v1 < v2 }