From dd39e85e19c673c6246ddc1925f0ca2fa17945a8 Mon Sep 17 00:00:00 2001 From: Bharathm1 <46574246+Bharathm1@users.noreply.github.com> Date: Mon, 14 Oct 2019 22:27:23 +0530 Subject: [PATCH] Added Pseudo code for partition --- readme | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/readme b/readme index 583ee9d..ac5f8b8 100644 --- a/readme +++ b/readme @@ -1,2 +1,27 @@ C implementation for sorting algorithms - - quick sort, heap sort, merge sort + - quick sort, heap sort, merge soRT + +/* 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 */ +partition (arr[], low, high) +{ + // pivot (Element to be placed at right position) + pivot = arr[high]; + + i = (low - 1) // Index of smaller element + + for (j = low; j <= high- 1; j++) + { + // If current element is smaller than the pivot + if (arr[j] < pivot) + { + i++; // increment index of smaller element + swap arr[i] and arr[j] + } + } + swap arr[i + 1] and arr[high]) + return (i + 1) +}