본문 바로가기

코딩테스트 준비/알고리즘

[알고리즘]선택정렬 with Python

선택정렬
                                                           비교데이터 인덱스      비교 시작 데이터 인덱스     비교끝 데이터 인덱스
5 4 3 1                                                           0                                 1                                   3
1 4 3 5  기준점 0번 최소값은1 첫번째 자리로 이동   1                                 2                                   3
1 3 4 5  기준점 1번                                           2                                 3                                   3



for stand in range(데이터길이  -1):
    lowest =stand
    for index in range(stand + 1, 데이터 길이):
       if data[lowest] > data[index]:
              lowest = index
    swap(lowest, stand)