int partition(int num, double a[], double cut) {
    double x;
    int i = 0, j = num - 1;

    while (i <= j) {
        while (i <= j && a[i] < cut) ++i;
        while (i <= j && a[j] >= cut) --j;
        if (i < j) {
            x = a[i];
            a[i] = a [j];
            a[j] = x;
            ++i;
            --j;
        }
    }
    
    return i;
}


