Python Program to Implement Bubble Sort
Bubble Sort is a sorting algorithm where we repeatedly iterate through the array and swap adjacent elements that are unordered.
- #Python program to implement Bubble sort
-
- def bubble_sort(a):
- for i in range(len(a) - 1, 0, -1):
- temp = True
- for j in range(0, i):
- if a[j + 1] < a[j]:
- a[j], a[j + 1] = a[j + 1], a[j]
- temp = False
- if temp:
- return
-
-
- a = input('Enter list elements: ').split()
- a = [int(x) for x in a]
-
- bubble_sort(a)
-
- print('Sorted list: ', end='')
- print(a)
Output

Solution not working or have any suggestions? Please send an email to [email protected]
Download Android App