#01 거품정렬 (bubble sort)
arr = [6,8,3,1,5,4,9,0,2,7] def bubblesort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] return arr def improved_bubblesort(arr): end_index = len(arr)-1 while end_index > 0 : swap = 0 for i in range(end_index): if arr[i] > arr[i+1] : arr[i], arr[i+1] = arr[i+1], arr[i] swap = i end_index = swap return arr - 서로 인접한 두 원소의 ..
2022. 1. 5.