Added breif comments on functions

This commit is contained in:
Ayaan Khan 2020-05-27 18:43:57 +05:30
parent 69f9210c17
commit c1764bd197

View File

@ -26,6 +26,12 @@
#include <cstdlib>
#include <iostream>
/* 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]; // taking the last element as pivot
int i = (low - 1); // Index of smaller element
@ -46,6 +52,10 @@ int partition(int arr[], int low, int high) {
return (i + 1);
}
/* The main function that implements QuickSort
arr[] --> Array to be sorted,
low --> Starting index,
high --> Ending index */
void quickSort(int arr[], int low, int high) {
if (low < high) {
int p = partition(arr, low, high);
@ -54,6 +64,7 @@ void quickSort(int arr[], int low, int high) {
}
}
// prints the array after sorting
void show(int arr[], int size) {
for (int i = 0; i < size; i++)
std::cout << arr[i] << " ";