Guest User

Untitled

a guest
Feb 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. def partition(lst, low,high, pivot,col):
  2.  
  3. lst[high],lst[pivot] = lst[pivot],lst[high]
  4. pivot = high
  5. i = low
  6. while i +1 <pivot:
  7. if lst[i][col] > lst[pivot][col]:
  8. lst[pivot], lst[pivot-1] = lst[pivot-1], lst[pivot]
  9. lst[i],lst[pivot] = lst[pivot],lst[i]
  10. pivot -= 1
  11. else:
  12. i +=1
  13. if lst[i][col] > lst[pivot][col]:
  14. lst[i],lst[pivot] = lst[pivot],lst[i]
  15. pivot -= 1
  16. return pivot
  17.  
  18. def quick(lst,low,high,col,ascending):
  19. count[0] += 1
  20. if low >= high:
  21. return
  22. else:
  23. #print(low,high)
  24. pivot = random.randint(low,high)
  25. #print(pivot)
  26. part_point = partition(lst,low,high,pivot,col)
  27. print(part_point,high)
  28. quick(lst,low,part_point-1,col,ascending)
  29. quick(lst,part_point+1, high,col, ascending)
Add Comment
Please, Sign In to add comment