Bubble Sort

Sort an array using the bubble sort algorithm by repeatedly swapping adjacent elements.

Code

Algorithms
a = arr.copy()
for i in range(len(a)):
    for j in range(len(a) - i - 1):
        if a[j] > a[j + 1]:
            a[j], a[j + 1] = a[j + 1], a[j]
return a

Parameters

Array to sort

Server

More Python Snippets