본문 바로가기
카테고리 없음

[알고리즘] 선택 정렬(selection sort)

by 소꿍 2021. 6. 21.

 

# selection sort

def selection_sort(data):
    for stand in range(len(data) - 1):
        lowest = stand
        for idx2 in range(stand + 1, len(data)):
            if data[idx2] < data[lowest]:
                lowest = idx2
        data[stand], data[lowest] = data[lowest], data[stand]
    return data
    
import random
data = random.sample(range(100), 10)

print(selection_sort(data))

댓글