def insertion_sort(values):
numvalues = len(values)
count = 0
while count < numvalues:
finished = False
current = count
moretosearch = current != 0
while moretosearch and not finished:
if values[current] < values[current - 1]:
temp = values[current]
values[current] = values[current - 1]
values[current - 1] = temp
current -= 1
moretosearch = current != 0
else:
finished = True
count += 1
최악의 경우
평균의 경우
def selection_sort(values):
endIndex = len(values) - 1
current = 0
while current < endIndex:
minval = min(values[current:])
minindex = values.index(minval, current)
temp = values[current]
values[current] = values[minindex]
values[minindex] = temp
current += 1
def exchange_sort(S):
n = len(S)
for i in range(n-1):
for j in range(i+1,n):
if S[i] > S[j]:
S[i], S[j] = S[j], S[i]
return S
exchange_sort(S)
print("정렬된 리스트 : ", S)