Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. __author__ = 'FraccaMan'
  2.  
  3. def mergeSort(alist,p):
  4. if len(alist)>1:
  5.  
  6. mid = len(alist)//2
  7. lefthalf = alist[:mid]
  8. righthalf = alist[mid:]
  9.  
  10. if mergeSort(lefthalf,p) == False:
  11. return False
  12. elif mergeSort(righthalf,p) == False:
  13. return False
  14.  
  15. i=0
  16. j=0
  17. c=0
  18.  
  19. while i<len(lefthalf) and j<len(righthalf):
  20. print(righthalf[j], lefthalf[i])
  21. if lefthalf[i] > righthalf[j]:
  22. #print('dioalemannocane')
  23. #print('schifodio',lefthalf[i] - righthalf[j])
  24. #print(p)
  25. if lefthalf[i] - righthalf[j] < p:
  26. #print('db')
  27. return False
  28. else:
  29. #print('dioalemannocanen2')
  30. if righthalf[j] - lefthalf[i] < p:
  31. #print('dc')
  32. return False
  33. if lefthalf[i]<righthalf[j]:
  34. print(lefthalf[i],righthalf[j])
  35. alist[c]=lefthalf[i]
  36. i=i+1
  37. else:
  38. alist[c]=righthalf[j]
  39. j=j+1
  40. c=c+1
  41.  
  42. while i<len(lefthalf):
  43. alist[c]=lefthalf[i]
  44. i=i+1
  45. c=c+1
  46.  
  47. while j<len(righthalf):
  48. alist[c]=righthalf[j]
  49. j=j+1
  50. c=c+1
  51. return True
  52.  
  53. a = [1,2,8,7,1]
  54.  
  55. print(mergeSort(a,3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement