Quicksort 1 - Partition

  • + 0 comments

    class Result {

    public static List<Integer> quickSort(List<Integer> arr) {
        int key = arr.get(0);
        int i = 0;
        for (int j = 1; j < arr.size(); j++) {
            if (arr.get(j) <= key) {
                i++;
                swap(arr, i, j);
            }
        }
        swap(arr, 0, i);
        return arr;
    }
    
    private static void swap(List<Integer> arr, int i, int j) {
        int temp = arr.get(i);
        arr.set(i, arr.get(j));
        arr.set(j, temp);
    }
    

    }