Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
33 changes: 33 additions & 0 deletions quick-sort/quick_sort.java
Original file line number Diff line number Diff line change
@@ -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;
}
}