Skip to content

Instantly share code, notes, and snippets.

@shitu13
Created May 17, 2024 18:04
Show Gist options
  • Save shitu13/46210d664fae492e51d521941d6e71a2 to your computer and use it in GitHub Desktop.
Save shitu13/46210d664fae492e51d521941d6e71a2 to your computer and use it in GitHub Desktop.
class Solution
{
public:
//Function to sort an array using quick sort algorithm.
void quickSort(int arr[], int low, int high)
{
if(low>=high){
return;
}
int pidx = partition(arr, low, high);
quickSort(arr, low, pidx-1);
quickSort(arr, pidx+1, high);
}
public:
int partition (int arr[], int low, int high)
{
int pivot = arr[high];
int pidx = low;
for(int i=low; i<high; i++){
if(arr[i]<=pivot){
swap(arr[i], arr[pidx++]);
}
}
swap(arr[pidx], arr[high]);
return pidx;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment