Created
September 17, 2018 05:56
-
-
Save afishr/1b711f4ff66354ebb8fd401269c6611f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quicksort | |
template <typename T> | |
void quicksort(T arr, int l, int r) | |
{ | |
int i, j; | |
i = l; | |
j = r; | |
int middle = arr[(i + j) / 2]; | |
do | |
{ | |
while (middle > arr[i]) | |
i++; | |
while (middle < arr[j]) | |
j--; | |
if ( i <= j) | |
{ | |
swap(arr[i], arr[j]); | |
i++; | |
j--; | |
} | |
} | |
while (i < j); | |
if (i < r) | |
quicksort(arr, i, r); | |
if (j > l) | |
quicksort(arr, l, j); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment