Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'FraccaMan'
- def mergeSort(alist,p):
- if len(alist)>1:
- mid = len(alist)//2
- lefthalf = alist[:mid]
- righthalf = alist[mid:]
- if mergeSort(lefthalf,p) == False:
- return False
- elif mergeSort(righthalf,p) == False:
- return False
- i=0
- j=0
- c=0
- while i<len(lefthalf) and j<len(righthalf):
- print(righthalf[j], lefthalf[i])
- if lefthalf[i] > righthalf[j]:
- #print('dioalemannocane')
- #print('schifodio',lefthalf[i] - righthalf[j])
- #print(p)
- if lefthalf[i] - righthalf[j] < p:
- #print('db')
- return False
- else:
- #print('dioalemannocanen2')
- if righthalf[j] - lefthalf[i] < p:
- #print('dc')
- return False
- if lefthalf[i]<righthalf[j]:
- print(lefthalf[i],righthalf[j])
- alist[c]=lefthalf[i]
- i=i+1
- else:
- alist[c]=righthalf[j]
- j=j+1
- c=c+1
- while i<len(lefthalf):
- alist[c]=lefthalf[i]
- i=i+1
- c=c+1
- while j<len(righthalf):
- alist[c]=righthalf[j]
- j=j+1
- c=c+1
- return True
- a = [1,2,8,7,1]
- print(mergeSort(a,3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement