Python 삽입정렬 구현

Jmnote (토론 | 기여)님의 2018년 8월 28일 (화) 03:46 판 (→‎개요)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Python 삽입정렬 구현
def insertion_sort(a):
	for i in range(1, len(a)):
		j=i-1
		temp=a[i]
		while j>=0 and a[j]>temp:
			a[j+1]=a[j]
			j-=1
		a[j+1]=temp
arr = [9,1,22,4,0,-1,1,22,100,10]
insertion_sort(arr)
print( arr )
# [-1, 0, 1, 1, 4, 9, 10, 22, 22, 100]

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}