Skip to content

Commit

Permalink
Update quick_sort.py
Browse files Browse the repository at this point in the history
Streamlining quick_sort function
  • Loading branch information
yyeltsyn authored Aug 29, 2016
1 parent abd9d78 commit 66433a5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions sorts/quick_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,20 @@ def quick_sort(collection):
>>> quick_sort([-2, -5, -45])
[-45, -5, -2]
"""
if len(collection) <= 1:
return collection
less = []
equal = []
greater = []
if len(collection) > 1:
pivot = collection[0]
for x in collection:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
return quick_sort(less) + equal + quick_sort(greater)
else:
return collection
pivot = collection[0]
for x in collection:
if x < pivot:
less.append(x)
elif x == pivot:
equal.append(x)
else:
greater.append(x)
return quick_sort(less) + equal + quick_sort(greater)


if __name__ == '__main__':
Expand Down

0 comments on commit 66433a5

Please sign in to comment.