Last active
August 29, 2015 14:09
-
-
Save prasadwrites/ef058315fb45e2a5d3ca to your computer and use it in GitHub Desktop.
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
#! /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