-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorter.py
58 lines (58 loc) · 999 Bytes
/
sorter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def mergesort(a):
if(len(a) <= 1):
return a
else:
left = a[0:len(a)/2]
right = a[len(a)/2:len(a)]
left = mergesort(left)
right = mergesort(right)
return merge(left,right)
def high_mergesort(a):
if(len(a) <= 1):
return a
else:
left = a[0:len(a)/2]
right = a[len(a)/2:len(a)]
left = high_mergesort(left)
right = high_mergesort(right)
return high_merge(left,right)
def merge(b, c):
result = []
l = b[:]
e = c[:]
i = 0
j = 0
while(len(l) != i or len(e) != j):
if(i == len(l)):
result += e[j:]
break
elif(j == len(e)):
result += l[i:]
break
elif(l[i] > e[j]):
result.append(e[j])
j+=1
else:
result.append(l[i])
i+=1
return result
def high_merge(b, c):
result = []
l = b[:]
e = c[:]
i = 0
j = 0
while(len(l) != i or len(e) != j):
if(i == len(l)):
result += e[j:]
break
elif(j == len(e)):
result += l[i:]
break
elif(l[i] > e[j]):
result.append(l[i])
i+=1
else:
result.append(e[j])
j+=1
return result