최적화버블정렬

    [알고리즘] bubble_sort 버블정렬(pseudo-code, 파이썬, Java)

    [알고리즘] bubble_sort 버블정렬(pseudo-code, 파이썬, Java)

    버블정렬 매 단계마다 처음부터 마지막까지 차례대로 인접한 두 원소를 비교하여 뒤에 있는 원소가 앞의 원소보다 작은 경우 두 원소를 교환 각 단계 수행 후 최대값이 마지막으로 이동하므로, 마지막 원소는 정렬대상에서 제외 Pseudo-code Algorithm bubbleSort(a, n) for i = n – 1 downto 1 for j = 0 to i-1 if(a[j] > a[j+1]) then int temp = a[index] a[index] = a[i] a[i] = temp Python def bubble_sort(arr): for i in range(len(arr)-1,0,-1): for j in range(i): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[..