수행 코드
arr = [40, 70, 60, 30, 10, 50]
print( " Initial Status = ", arr)
for i in range(len(arr)-1):
print( "i = ", i)
small_idx = i
for j in range(i+1, len(arr)): #comparion
print( small_idx)
if arr[small_idx]>arr[j]:
small_idx = j
arr[i], arr[small_idx] = arr[small_idx], arr[i] #swap
print( " small_idx = ", small_idx )
print( " Partial Result = ", arr)
print("Final: ")
print(arr)
수행결과 화면
PS D:\PythonCode> python .\SelectionSorting.py
Initial Status = [40, 70, 60, 30, 10, 50]
i = 0
0
0
0
3
4
small_idx = 4
Partial Result = [10, 70, 60, 30, 40, 50]
i = 1
1
2
3
3
small_idx = 3
Partial Result = [10, 30, 60, 70, 40, 50]
i = 2
2
2
4
small_idx = 4
Partial Result = [10, 30, 40, 70, 60, 50]
i = 3
3
4
small_idx = 5
Partial Result = [10, 30, 40, 50, 60, 70]
i = 4
4
small_idx = 4
Partial Result = [10, 30, 40, 50, 60, 70]
Final:
[10, 30, 40, 50, 60, 70]
PS D:\PythonCode>
수행결과 분석