자료구조(data structure)

정렬 알고리즘 - 버블정렬(bubble sort) - 파이썬(python)

진한색 2022. 12. 24. 12:38

시간복잡도: O(n^2)

 

def bubble_sort_improve(lists): 
                                
    global count1
    n=len(lists)

    for loop in range(n-1):
        change=False
        for i in range(n-loop-1):
            if lists[i]>lists[i+1]:
                lists[i],lists[i+1]=lists[i+1],lists[i]
                count1+=1
                change=True
        if change==False:
            break
 

 

728x90