Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #3.5 (102)Bubble sort Python coded by Ken Adams
- my_list = [5,9,5,8,1,3] #list to be sorted
- print("The unsorted list")
- print(my_list)
- def bubble_sort(any_list):
- sorted_list = any_list[:]
- swapped = True
- while swapped == True:
- swapped = False
- for i in range(len(sorted_list) - 1):
- if sorted_list[i] > sorted_list[i+1]:
- sorted_list[i], sorted_list[i+1] = sorted_list[i+1], sorted_list[i]
- swapped = True
- return sorted_list
- sorted = bubble_sort(my_list)
- print("\nnow the sorted list")
- print(sorted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement