DSA/sorting/python/bubble-sort.py

22 lines
386 B
Python
Raw Normal View History

arr = [23, 34, 25, 12, 54, 11, 90]
2020-12-31 15:00:49 +00:00
def bubbleSort(arr):
"""
>>> bubbleSort(arr)
[11, 12, 23, 25, 34, 54, 90]
"""
n = len(arr)
for i in range(n-1):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
2020-12-31 15:00:49 +00:00
bubbleSort(arr)
print("Sorted array is:")
2021-04-12 10:02:56 +00:00
for item in arr:
print(item)