Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. my_list = [5, 9, 5, 8, 1, 3]
  2.  
  3. def bubble_sort(unsorted):
  4.     sorted = my_list[:]
  5.     swapped = True
  6.     while swapped is True:
  7.         swapped = False
  8.         for i in range(len(sorted) -1):
  9.             if sorted[i] > sorted[i+1]:
  10.                 sorted[i], sorted[i+1] = sorted[i+1], sorted[i]
  11.                 swapped = True
  12.     return sorted
  13.  
  14. bubble_sort(my_list)
  15.  
  16. print("My list = ", my_list)
  17. print("Sorted list = ", bubble_sort(my_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement