Advertisement
Mori007

MyBubblesortList

May 12th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. y_list = [5,9,5,8,1,3]
  2.  
  3. def bubble_sort(unsorted):
  4. sorted = unsorted[:]
  5. swapped = True
  6. while swapped == 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. my_newlist = bubble_sort(my_list)
  15. print('Sorting of list {}'.format(my_newlist))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement