Quicksort 1 - Partition

  • + 0 comments

    Java:

    public static List<Integer> quickSort(List<Integer> arr) {
      // Write your code here
      int pivot = arr.get(0);
      List<Integer> left = new ArrayList<>();
      List<Integer> right = new ArrayList<>();
      for (Integer i : arr) {
        if (i < pivot) {
          left.add(i);
        } else if (i > pivot) {
          right.add(i);
        }
      }
      left.add(pivot);
      left.addAll(right);
      return left;
    }