-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathtusc5.py
More file actions
38 lines (36 loc) · 897 Bytes
/
tusc5.py
File metadata and controls
38 lines (36 loc) · 897 Bytes
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
def soedsort(a):
if len(a) > 1:
mid = len(a) // 2
left = a[:mid]
right = a[mid:]
soedsort(left)
soedsort(right)
i = j = l = 0
while i < len(left) and j < len(right):
if left[i] < right[j]:
a[l] = left[i]
i += 1
else:
a[l] = right[j]
j += 1
l += 1
while i < len(left):
a[l] = left[i]
i += 1
l += 1
while j < len(right):
a[l] = right[j]
j += 1
l += 1
def sortbis(a):
if len(a) <= 1:
return a
else:
st = a[0]
men = [x for x in a[1:] if x <= st]
bol = [x for x in a[1:] if x > st]
return sortbis(men) + [st] + sortbis(bol)
n = int(input())
num = list(map(int, input().split()))
soedsort(num)
result = []