Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my_list = [5, 9, 5, 8, 1, 3]
- def bubble_sort(unsorted):
- sorted = my_list[:]
- swapped = True
- while swapped is True:
- swapped = False
- for i in range(len(sorted) -1):
- if sorted[i] > sorted[i+1]:
- sorted[i], sorted[i+1] = sorted[i+1], sorted[i]
- swapped = True
- return sorted
- bubble_sort(my_list)
- print("My list = ", my_list)
- print("Sorted list = ", bubble_sort(my_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement