Example #1
0
/***************************************************************************************************** 
  Partition Function in the quickSort Algorithm. It returns the indices j such that all the elements before j in the vector
	 a are less than or equal to those after j.	 
*/
int partition( double a[], int indices[], int l, int r) {
   register int i, j;
   double pivot;
   pivot = a[l];
   i = l; j = r+1;		
   while(1)
   {
   	do ++i; while( a[i] <= pivot && i <= r );
   	do --j; while( a[j] > pivot );
   	if( i >= j ) break;
   	swap_d(&a[i], &a[j]);
   	swap(&indices[i], &indices[j]);     	
   } 
   swap_d(&a[l], &a[j]);
   swap(&indices[l], &indices[j]);
   return j;
}
Example #2
0
void sortByProb(double *prob, int *geno, int n)
{
  int    i, j;

  for (i=1; i<n; i++)
    for (j=i; (j > 0) && (prob[j] > prob[j-1]); j--) {
      swap_d(&prob[j], &prob[j-1]);
      swap_i(&geno[j], &geno[j-1]);
    }
}