import random
def selectionSort(arr):
for i in range(len(arr)):
min_index = i
# print(arr)
for j in range(i, len(arr)):
if arr[j] < arr[min_index]:
min_index = j
arr[i], arr[min_index] = arr[min_index], arr[i]
return arr
두 인접한 원소를 검사하여 정렬하는 방법
import random
def bubbleSort(arr):
for i in range(len(arr)):
print(arr)
for j in range(len(arr)-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
장점