ModdersCentral

Full Version: Python Sorting algorithm
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Bubble Sort

Code:
def BubbleSort(arr):
    swapped = True
    while swapped == True:
        swapped = False
        for i in range(len(arr) - 1): 
            if arr[i] > arr[i + 1]:
                arr[i], arr[i+1] = arr[i+1], arr[i]
                swapped = True


arr = [45, 30, 25, 10, 5, 18, 70]
BubbleSort(arr)
for i in range(len(arr)):
    print(arr[i])
www.000webhost.com