Advertisement
xavicano

Untitled

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