Skip to content

Instantly share code, notes, and snippets.

@prasadwrites
Last active August 29, 2015 14:09
Show Gist options
  • Save prasadwrites/ef058315fb45e2a5d3ca to your computer and use it in GitHub Desktop.
Save prasadwrites/ef058315fb45e2a5d3ca to your computer and use it in GitHub Desktop.
#! /usr/env/path python
items = [2,5,6,7,8,5,0,1,2,3,4]
def quick_sort(items):
""" Implementation of quick sort """
if len(items) > 1:
pivot_index = len(items) // 2
smaller_items = []
larger_items = []
for i, val in enumerate(items):
if i != pivot_index:
if val < items[pivot_index]:
smaller_items.append(val)
else:
larger_items.append(val)
quick_sort(smaller_items)
quick_sort(larger_items)
items[:] = smaller_items + [items[pivot_index]] + larger_items
print(items)
quick_sort(items)
print(items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment