Topic Text   Topic Comments (5)   Topic Properties   Topic Information alecito13@hot...
Topic title: My Test Tuesday April 2, 2013 18:04:13

Download topic text | View in monospace font | Tab width set to 8 (change to 4)

Files in topic:  
[Jump to] merged_sort.py   {+27,-0}

[Add General Comment] to topic.

File merged_sort.py (Revision 1.0) [Add File Comment] [Top]
 
1 import time
2
3 def merge_list(left, right):
4 merged_list = []
5 while(True):
6 if left == [] or right == []:
7 merged_list = merged_list + right + left
8 break
9 if left[0] < right[0]:
10 merged_list.append(left.pop(0))
11 elif left[0] > right[0]:
12 merged_list.append(right.pop(0))
13 else:
14 merged_list.append(right.pop(0))
15 merged_list.append(left.pop(0))
16 return merged_list
17
18 def merge_sort(A,p,r):
19 mid = int(len(A[p:r])/2);
20 if mid == 0:
21 return A[p:r]
22 left = merge_sort(A,p,p+mid)
23 right = merge_sort(A,p+mid,r)
24 return merge_list(left,right)
25
26 l = input().split()
27 print( merge_sort(list(map(int,l)),0,len(l)) )
 
  
Legend:
Removed 
Changed
 Added

[Add General Comment] to topic.