-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSORT_EX.py
More file actions
35 lines (28 loc) · 900 Bytes
/
Copy pathSORT_EX.py
File metadata and controls
35 lines (28 loc) · 900 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
# n = int(input())
# L = []
# for i in range(n):
# num = int(input())
# if n <100000 and n> 0:
# L.append(num)
# L.sort()
#L.reterse()
# print(*L)
n = int(input())
L = []
for i in range(n):
num = int(input())
if n <100000 and n> 0:
L.append(num)
def quick_sort(array):
# 리스트가 하나 이하의 원소만을 담고 있다면 종료
if len(array) <= 1:
return array
pivot = array[0] # 피벗은 첫 번째 원소
tail = array[1:] # 피벗을 제외한 리스트
left_side = [x for x in tail if x <= pivot] # 분할된 왼쪽 부분
right_side = [x for x in tail if x > pivot] # 분할된 오른쪽 부분
# 분할 이후 왼쪽 부분과 오른쪽 부분에서 각각 정렬 수행하고, 전체 리스트 반환
return quick_sort(left_side) + [pivot] + quick_sort(right_side)
arr = quick_sort(L)
arr.reverse()
print(*arr)