コード例 #1
0
ファイル: hyb.c プロジェクト: KonstantinosKr/cvxlb
/* approximate median of a point set */
static BOX* median (BOX **Pb, BOX **Pe, int d, int h)
{
  if (h == 0) return *(Pb + rand () % (Pe-Pb));
  else return median_of_three (median (Pb, Pe, d, h-1),
                               median (Pb, Pe, d, h-1),
                               median (Pb, Pe, d, h-1), d);
}
コード例 #2
0
ファイル: QuickSort.cpp プロジェクト: limingjie/algorithm
void quicksort(T *arr, int left, int right)
{
    int pivot;

    if (left < right)
    {
        median_of_three(arr, left, right);
        // pivot = hoare_partition(arr, left, right); // about 10%~15% slower, why?
        pivot = partition(arr, left, right);
        quicksort(arr, left, pivot - 1);
        quicksort(arr, pivot + 1, right);
    }
}