Skip to content

Commit

Permalink
선택정렬과 삽입정렬 구현 코드 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
heerucan committed Feb 15, 2022
1 parent 826f169 commit 0b261fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CodingTest/CH6 정렬/삽입정렬.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 삽입정렬 소스코드

lists = [8, 3, 2, 7, 6]

for i in range(1, len(lists)):
j = i
while j > 0 and lists[j-1] > lists[j]:

lists[j-1], lists[j] = lists[j], lists[j-1]
j -= 1

print(lists)

14 changes: 14 additions & 0 deletions CodingTest/CH6 정렬/선택정렬.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 선택 정렬 소스코드

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[min_index] > array[j]:
min_index = j

array[i], array[min_index] = array[min_index], array[i] #스와프

print(array)

0 comments on commit 0b261fa

Please sign in to comment.