Write a program to sort a list using bubblesort


Topic: Write a program to sort a list using bubblesort

Solution

def bubblesort(arr):
    n = len(arr)
    for i in range(n - 1):
        for j in range(n - i - 1):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
    return arr
print(bubblesort([1, 33, 192, 21, 0]))



List all Python Programs