private static int partition(int[] array, int start, int end) {
        int center = (start + end) / 2;
        //mediaan van 3
        if (array[center] < array[start]) {
            swap(array, center, start);
        }
        if (array[end] < array[start]) {
            swap(array, start, end);
        }
        if (array[end] < array[center]) {
            swap(array, center, end);
        }

        int pivotIndex = center;

        //spil achteraan
        swap(array, pivotIndex, end - 1);

        int pivot = array[end - 1];
        int left = start;
        int right = end - 1;
        while (array[++left] < pivot);
        while (pivot < array[--right]);

        while (left < right) {
            swap(array, left, right);
            while (array[++left] < pivot);
            while (pivot < array[--right]);
        }

        pivotIndex = left;
        swap(array, pivotIndex, end - 1);
        return pivotIndex;
    }