Случайная сводная быстрая сортировка в Java [duplicate]

Возможный дубликат:

Быстрая сортировка со случайным поворотом в Java

Приведенный ниже код быстрой сортировки использует первый элемент массива в качестве сводной, а затем сортирует массив. Теперь я хочу случайным образом выбрать сводную точку вместо первой, а затем отсортировать массив, и я застрял, скажите, пожалуйста, какие изменения я могу внести в приведенный ниже код, чтобы получить идеальные результаты.

import java.util.*;
import javax.swing.JOptionPane;

public class Quicksort {

public static void main(String[] args) {
    String arraylength = JOptionPane.showInputDialog("Enter the length of the array.");

    int a = Integer.parseInt(arraylength);
    if (a == 0) {
        System.out.println("Null Length");
    } else {
        int[] list = new int[a];


        for (int i = 0; i < a; i++) {
            String input = JOptionPane.showInputDialog("Input the number.");
            int c = Integer.parseInt(input);
            list[i] = c;
        }

        System.out.println("Before");
        for (int i = 0; i < list.length; i++) {
            System.out.print(list[i] + " ");
        }
        partition(list, 0, list.length - 1);


        System.out.println("\nAfter partitionaing");
        for (int i = 0; i < list.length; i++) {
            System.out.print(list[i] + " ");
        }
        quickSort(list, 0, list.length - 1);

        System.out.println("\nAfter Sorting");
        for (int i = 0; i < list.length; i++) {
            System.out.print(list[i] + " ");
        }
    }
}

private static int partition(int[] list, int first, int last) {
    int pivot = list[first];
    int low = first + 1;
    int high = last;

    while (high > low) {

        while (low < high && list[low] < pivot) {
            low++;
        }


        while (low < high && list[high] >= pivot) {
            high--;
        }


        if (high > low) {
            int temp = list[high];
            list[high] = list[low];
            list[low] = temp;
        }
    }
    while (high > first && list[high] >= pivot) {
        high--;
    }

    if (pivot > list[high]) {
        list[first] = list[high];
        list[high] = pivot;
        return high;
    } else {
        return first;
    }

}

private static void quickSort(int[] list, int first, int last) {
    if (last > first) {
        int pivotIndex = partition(list, first, last);
        quickSort(list, first, pivotIndex - 1);
        quickSort(list, pivotIndex + 1, last);
    }
}
}

Ответы на вопрос(3)

Ваш ответ на вопрос