From b80e07685c8a01c456118abe2c855e3503c089e4 Mon Sep 17 00:00:00 2001 From: Sandali Samarawickrama Date: Tue, 2 Oct 2018 08:41:29 +0530 Subject: [PATCH] Add QuickSort.java --- sorting/QuickSort.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sorting/QuickSort.java diff --git a/sorting/QuickSort.java b/sorting/QuickSort.java new file mode 100644 index 0000000..736af0a --- /dev/null +++ b/sorting/QuickSort.java @@ -0,0 +1,30 @@ +/** + * Java implementation of quick sort + * + * @author Sandali Samarawickrama + */ + +class QuickSort +{ + /* This function takes last element as pivot, + places the pivot element at its correct + position in sorted array, and places all + smaller (smaller than pivot) to left of + pivot and all greater elements to right + of pivot */ + int partition(int arr[], int low, int high) + { + int pivot = arr[high]; + int i = (low-1); + for (int j=low; j