void d_sort(distance **d, int size) { int i=0, j=0; rep(i,size) tper(j,size-1,i) if ( d_compare(d[j],d[j-1]) > 0 ) d_swap(d[j-1],d[j]); }
void QuickSort(double *pdBufferX, double *pdBufferY, double *pdBufferComp, int left, int right) { // left is the lower index, right is the upper index // of the region of array a that is to be sorted int i=left, j=right; double pivot = pdBufferComp[(left+right)/2]; // partition while(i <= j) { while (pdBufferComp[i]<pivot) i++; while (pdBufferComp[j]>pivot) j--; if (i<=j) { d_swap(pdBufferX[i], pdBufferX[j]); d_swap(pdBufferY[i], pdBufferY[j]); i++; j--; } } // recursion if (left<j) QuickSort(pdBufferX, pdBufferY, pdBufferComp, left, j); if (i<right) QuickSort(pdBufferX, pdBufferY, pdBufferComp, i, right); } // QuickSort()
void QuickSort(double **ppdBuffer, double *pdBufferZ, int nDimensions, int left, int right) { //void Evidence::QuickSort(double *pdBufferX, double *pdBufferY, double *pdBufferZ, int *pnBufferI, int *pnBufferComp, int left, int right) { // left is the lower index, right is the upper index // of the region of array a that is to be sorted int i=left, j=right, d; double pivot = pdBufferZ[(left+right)/2]; // partition while(i <= j) { while (double(pdBufferZ[i])<pivot) i++; while (double(pdBufferZ[j])>pivot) j--; if (i<=j) { d_swap(pdBufferZ[i], pdBufferZ[j]); for(d=0; d<nDimensions; d++) d_swap(ppdBuffer[i][d], ppdBuffer[j][d]); i++; j--; } // if i<=j } // while i<=j // recursion if (left<j) QuickSort(ppdBuffer, pdBufferZ, nDimensions, left, j); if (i<right) QuickSort(ppdBuffer, pdBufferZ, nDimensions, i, right); } // QuickSort()