Skip to content

Instantly share code, notes, and snippets.

@roshangautam
Last active September 25, 2017 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roshangautam/ce1b66894a879a670d2be605c9b8b48f to your computer and use it in GitHub Desktop.
Save roshangautam/ce1b66894a879a670d2be605c9b8b48f to your computer and use it in GitHub Desktop.
Quick Sort - Python
def quicksort(array, first, last):
if first < last :
pivot = array[first]
left = first + 1
right = last
while 1 :
while left <= right and array[left] <= pivot :
left += 1
while right >= left and array[right] >= pivot :
right -= 1
if right < left : break
temp = array[left]
array[left] = array[right]
array[right] = temp
array[first] = array[right]
array[right] = pivot
quicksort(array, first, right - 1)
quicksort(array, right + 1, last)
test = [21, 4, 1, 3, 9, 20, 25, 6, 21, 14]
quicksort(test, 0 , len(test)-1)
print test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment