bubble Sort in Python

this is second weeks in algorithm study,

I want learn python and study basic algorithm.

this time I studied Bubble sort.
this time complexity is always O(N^2).
next time I will rewrite optimized Bubble sort  

arr =  [5, 1, 4, 2, 8]

def swap(arr, a, b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

def bubblesort(arr):
    for i in range(len(arr)) :
        print( str(i+1) + " 번재 passing");
        for j in range(len(arr)-1):
            if arr[j] > arr[j+1] :
                swap(arr, j, j+1);

bubblesort( arr);
print("result : ")


Popular posts from this blog

codefights smooth sailing ( CommonCharacterCount)

How to remove 8443 port in URL in tomcat