diff --git a/algorithms/src/main/java/com/baeldung/algorithms/quicksort/QuickSort.java b/algorithms/src/main/java/com/baeldung/algorithms/quicksort/QuickSort.java new file mode 100644 index 0000000000..e113cc3242 --- /dev/null +++ b/algorithms/src/main/java/com/baeldung/algorithms/quicksort/QuickSort.java @@ -0,0 +1,39 @@ +package com.baeldung.algorithms.quicksort; + +public class QuickSort { + + public static void quickSort(int arr[], int begin, int end) + { + if (begin < end) { + int partitionIndex = partition(arr, begin, end); + + // Recursively sort elements of the 2 sub-arrays + quickSort(arr, begin, partitionIndex-1); + quickSort(arr, partitionIndex+1, end); + } + } + + private static int partition(int arr[], int begin, int end) + { + int pivot = arr[end]; + int i = (begin-1); + + for (int j=begin; j