Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- list = [6,7,5,8,3,1,2,4]
- def divide(list):
- if len(list) <= 1:
- return list
- else:
- mid = int(len(list)/2)
- flist = divide(list [:mid])
- llist = divide(list [mid:])
- return merge(flist,llist)
- def merge(flist,llist):
- i = j = 0; list =[]
- while i<len(flist) and j < len(llist):
- if flist[i] < llist[j]:
- list.append(flist[i])
- i += 1
- else:
- list.append(llist[j])
- j += 1
- def main(list):
- return divide(list)
- print main(list)
- ################## END of CODE ###################
- #====================================================================================================#
- The output is:
- Traceback (most recent call last):
- File "./code/python/personal/merge sort", line 27, in <module>
- print main(list)
- File "./code/python/personal/merge sort", line 25, in main
- return divide(list)
- File "./code/python/personal/merge sort", line 10, in divide
- flist = divide(list [:mid])
- File "./code/python/personal/merge sort", line 12, in divide
- return merge(flist,llist)
- File "./code/python/personal/merge sort", line 17, in merge
- while i<len(flist) and j < len(llist):
- TypeError: object of type 'NoneType' has no len()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement