Skip to content

Instantly share code, notes, and snippets.

@reterVision
Created January 12, 2014 02:45
Show Gist options
  • Save reterVision/1620e7d82517fe0d9f9d to your computer and use it in GitHub Desktop.
Save reterVision/1620e7d82517fe0d9f9d to your computer and use it in GitHub Desktop.
Quick Sort
"""
Quick Sort
"""
def quick_sort(array):
if len(array) <= 1:
return array
pivot = array[0]
array = array[1:]
left, right = [], []
for item in array:
if item <= pivot:
left.append(item)
else:
right.append(item)
return quick_sort(left) + [pivot] + quick_sort(right)
if __name__ == "__main__":
array = [7, 5, 4, 1, 2, 3, 9, 8, 10]
print quick_sort(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment