Advertisement
SetKaung

Bubble Sort

Mar 13th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. def bubble_sort(elements):
  2.     swapped = True
  3.     while swapped:
  4.         swapped = False
  5.         for i in range(1,len(elements)):
  6.             if elements[i] < elements[i-1]:
  7.                 elements[i], elements[i-1] = elements[i-1], elements[i]
  8.                 swapped = True
  9.                
  10.    
  11.  
  12. numbers = [5,1,4,7,2,3,8,0,6]
  13.  
  14. bubble_sort(numbers)
  15. print(numbers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement