Quick Sort

Reference:

  1. Sorting algorithms/Quicksort
  2. Quicksort

C code:

void QuickSort(int *array, int size)
{
    int i, j, p, temp;

    if(size<2)
        return;
    p = array[size/2];

    for(i=0, j=size-1;;i++,j--) {
        while(array[i]<p)   i++;
        while(array[j]>p)   j--;
        if(i>=j)            break;
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    QuickSort(array, i);
    QuickSort(array+i, size-i);
}

results matching ""

    No results matching ""