Advertisement
Peaser

Quick sort implementation

Jul 6th, 2015
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # How this is going to work:
  2.  
  3. #   for each item in the list:
  4. #     if the item is greater than the item to the right of it:
  5. #       switch places between the two
  6. #     start over; repeat
  7.  
  8. # eventually it will be sorted.
  9.  
  10. def qksort(data):
  11.   iteration = 1
  12.   while iteration < len(data):
  13.     for key, value in enumerate(data):
  14.       if key != len(data) - 1:
  15.         if value > data[key + 1]:
  16.           data[key], data[key + 1] = data[key + 1], data[key]
  17.     iteration += 1
  18.   return data
  19.  
  20.  
  21. example = [5,1,6,2,4,8,0]
  22. print qksort(example)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement