Created
March 26, 2016 23:02
-
-
Save TwiN/77313954e2afb1fe2024 to your computer and use it in GitHub Desktop.
Java quick sort
This file contains hidden or 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
public static void quickSort(int myList[], int left, int right) { | |
int temp, i = left, j = right; | |
int pivot = myList[(left+right)/2]; | |
do { | |
while(myList[i] < pivot) i++; | |
while(pivot < myList[j]) j--; | |
if (i <= j) { | |
temp = myList[i]; | |
myList[i] = myList[j]; | |
myList[j] = temp; | |
i++; | |
j--; | |
} | |
} while (i <= j); | |
if (left<j) quickSort(myList, left, j); | |
if (i<right) quickSort(myList, i, right); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment