자료구조(data structure)
정렬 알고리즘 - 선택정렬(selection sort) - 파이썬(python)
진한색
2022. 12. 24. 11:53
선택정렬 시간복잡도: O(n^2)
def selection_sort(lists):
global count2
n=len(lists)
s=0 # smallest index
for loop in range(n-1):
s=loop
for i in range(loop+1,n):
if lists[s]>lists[i]:
s=i
lists[s],lists[loop] =lists[loop],lists[s]
count2+=1
728x90