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.

  1. #Python program to implement Bubble sort
  2. def bubble_sort(a):
  3. for i in range(len(a) - 1, 0, -1):
  4. temp = True
  5. for j in range(0, i):
  6. if a[j + 1] < a[j]:
  7. a[j], a[j + 1] = a[j + 1], a[j]
  8. temp = False
  9. if temp:
  10. return
  11. a = input('Enter list elements: ').split()
  12. a = [int(x) for x in a]
  13. bubble_sort(a)
  14. print('Sorted list: ', end='')
  15. print(a)

Please click on the like button if it worked

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

Join Our Facebook Group

Share this example

Download Android App is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube