본문 바로가기
알고리즘 풀이/정렬 알고리즘

정렬 알고리즘 _ 선택정렬

by developer jini 2022. 12. 29.
728x90
array = [7, 5, 9, 0, 3, 1, 6, 2, 4, 8]

for i in range(len(array)):
    min_index = i # 가장 작은 원소
    for j in range(i + 1, len(array)):
        if array[j] < array[min_index]:
            min_index = j
    array[i], array[min_index] = array[min_index], array[i]#스와프

print(array)

 

728x90

댓글