diff --git a/README.md b/README.md index d8ee2f1..08d2794 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,4 @@ Also add your name to the contributors part. * [Lampa](https://github.com/swetlana-spb) * Oleksii Ovdiienko * [Kayacan](https://github.com/kayacanv) +* [Henning Hausenberg] (https://digital.edeka/) diff --git a/quick-sort/quick_sort.java b/quick-sort/quick_sort.java new file mode 100644 index 0000000..9d72e03 --- /dev/null +++ b/quick-sort/quick_sort.java @@ -0,0 +1,33 @@ +public class Quicksort{ + + public int[] quickSort(int arr[], int begin, int end) { + if (begin < end) { + int partitionIndex = partition(arr, begin, end); + + quickSort(arr, begin, partitionIndex-1); + quickSort(arr, partitionIndex+1, end); + } + return arr; + } + + private int partition(int arr[], int begin, int end) { + int pivot = arr[end]; + int i = (begin-1); + + for (int j = begin; j < end; j++) { + if (arr[j] <= pivot) { + i++; + + int swapTemp = arr[i]; + arr[i] = arr[j]; + arr[j] = swapTemp; + } + } + + int swapTemp = arr[i+1]; + arr[i+1] = arr[end]; + arr[end] = swapTemp; + + return i+1; + } +} \ No newline at end of file