Advertisement
Fareehausman00

Untitled

Sep 21st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. my_list = [5,9,5,8,1,3]
  2.  
  3. def bubblesort(unsorted):
  4. my_list_copy = unsorted[:]
  5. swap = True
  6. while swap == True:
  7. swap = False
  8. for i in range(len(my_list_copy)-1):
  9. if my_list_copy[i] > my_list_copy[i+1]:
  10. my_list_copy[i], my_list_copy[i+1] = my_list_copy[i+1], my_list_copy[i]
  11. swap = True
  12. return my_list_copy
  13.  
  14. print(bubblesort(my_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement