Advertisement
Guest User

Untitled

a guest
May 29th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. # Quick Sort
  2.  
  3. def partition(alist, first, last):
  4. pivotvalue = alist[first]
  5.  
  6. leftmark, rightmark = first+1, last
  7.  
  8. done = False
  9. while not done:
  10. while leftmark <= rightmark and \
  11. alist[leftmark] < pivotvalue:
  12. leftmark = leftmark + 1
  13. while alist[rightmark] > pivotvalue and \
  14. rightmark >= leftmark:
  15. rightmark = rightmark -1
  16. if rightmark < leftmark:
  17. done = True
  18. else:
  19. alist[leftmark],alist[rightmark]= \
  20. alist[rightmark],alist[leftmark]
  21.  
  22. alist[first],alist[rightmark]= \
  23. alist[rightmark],alist[first]
  24.  
  25. return rightmark
  26.  
  27. def quickSort(alist):
  28. quickSortHelper(alist,0,len(alist)-1)
  29.  
  30. def quickSortHelper(alist,first,last):
  31. if first < last:
  32. splitpoint = partition(alist,first,last)
  33.  
  34. quickSortHelper(alist,first,splitpoint-1)
  35. quickSortHelper(alist,splitpoint+1,last)
  36.  
  37. # Medyan hesabı
  38.  
  39. def medyan(liste):
  40. if len(liste) % 2 == 1:
  41. return liste[int(len(liste) / 2)]
  42. else:
  43. orta = int(len(liste) / 2)
  44. return (liste[orta] + liste[orta-1]) / 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement