Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Bubble sort
- my_list = [100,6,3,21,76,1,99,88,22,54,45,7,9,11]
- #Bubble sort function
- def bubble_sort(unsorted_list):
- sorted_list=unsorted_list[:] #Make a copy of the original unsorted list
- swapped = True
- while swapped:
- swapped=False
- for i in range(len(sorted_list) - 1):
- if sorted_list[i] > sorted_list[i+1]: #go throught the copy of the list and check if each number is smalled than the one after it
- sorted_list[i],sorted_list[i+1] = sorted_list[i+1], sorted_list[i] #if the number is larger then swap the places
- swapped = True
- return sorted_list
- print(bubble_sort(my_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement