Skip to content

Instantly share code, notes, and snippets.

@HaiFongPan
Created October 13, 2012 12:03
Show Gist options
  • Save HaiFongPan/3884352 to your computer and use it in GitHub Desktop.
Save HaiFongPan/3884352 to your computer and use it in GitHub Desktop.
quick sort algorithm
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