Created
October 13, 2012 12:03
-
-
Save HaiFongPan/3884352 to your computer and use it in GitHub Desktop.
quick sort algorithm
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
def split(array,first,last): | |
left = first | |
right = last | |
while left < right: | |
while array[first] < array[right]: | |
right -= 1 | |
while array[first] >= array[left] and left < right: | |
left += 1 | |
if left < right: | |
array[left],array[right] = array[right],array[left] | |
array[first],array[left] = array[left],array[first] | |
return left | |
def quickSort(array,first,last): | |
if first < last: | |
pos = split(array,first,last) | |
quickSort(array,first,pos-1) | |
quickSort(array,pos+1,last) | |
return array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment