import sys
def mergeSort(A, s, e):
half = (s+e) // 2
mergeSort(A, s, half)
mergeSort(A, half+1, e)
merge(A, s, half, e)
def merge(A, s, half, e):
tmp = []
i = s
j = half+1
while i <= half and j <= e:
if A[i] < A[j]:
tmp.append[A[i]]
i += 1
while i <= half:
tmp.append[A[i]]
i += 1
while j <= e:
tmp.append[A[j]]
j += 1
i = s
j = 0
while i <= e:
A[i] = tmp[j]
i += 1
j += 1
sys.setrecursionlimit(10000)
A = [31, 3, 65, 73, 8, 11, 20, 29, 48, 15]
mergeSort(A, 0, len(A))
print(A)
'CS > 알고리즘' 카테고리의 다른 글
Quick Sort in Python (퀵 정렬) (0) | 2020.06.09 |
---|---|
Insertion Sort in Python (삽입 정렬) (0) | 2020.06.09 |
크루스칼 알고리즘 (Python) (0) | 2020.05.07 |
프림 알고리즘 (Python) (0) | 2020.05.07 |
Call by Value vs Call by Reference (0) | 2020.04.28 |