Advertisement
DarkPotatoKing

quick_sort.py

Oct 8th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. '''
  2. Kyle C. Rosales
  3. October 8, 2014
  4. Quick Sort
  5. '''
  6. def quick_sort(ls):
  7.     if len(ls) <= 1: return ls
  8.     pivot_val = ls[0]
  9.     less, equal, greater = [], [], []
  10.     for i in ls:
  11.         if i < pivot_val: less.append(i)
  12.         elif i == pivot_val: equal.append(i)
  13.         else: greater.append(i)
  14.     return quick_sort(less) + equal + quick_sort(greater)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement