Algorithm/정렬
[python] 삽입 정렬(Insertion sort)
Potato potage
2022. 3. 21. 14:47
반응형
내용 정리 ➡ https://good-potato.tistory.com/38
[C++] 삽입 정렬(Insertion Sort)
삽입 정렬 정렬되어 있는 리스트에 새로운 레코드를 적절한 위치에 삽입하는 과정을 반복한다. 정렬되어 있지 않은 부분의 첫 번째 숫자가 정렬된 부분의 어느 위치에 삽입되어야 하는가를 판
good-potato.tistory.com
코드 정리
#삽입 정렬
def insertion(arr):
n = len(arr)
for i in range(1, n):
j = i
temp = arr[i]
while j > 0 and arr[j-1] > temp:
arr[j] = arr[j - 1]
j -= 1
arr[j] = temp
반응형