Advertisement
timber101

ColinBubbleSort

Dec 27th, 2020
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. #  colins Bubble sort
  2.  
  3. my_list = [3,6,8,1,4,6,9,2,6,0,-3]
  4.  
  5. def bubblesort(unsorted):
  6.     my_sorted_list = my_list[:]
  7.     swapped = True
  8.     while swapped:
  9.         swapped = False
  10.         for i in range(len(my_sorted_list)-1):
  11.             if my_sorted_list[i] > my_sorted_list[i+1]:
  12.                 my_sorted_list[i], my_sorted_list[i+1] = my_sorted_list[i +1], my_sorted_list[i]
  13.                 swapped = True
  14.         print(my_sorted_list)
  15.  
  16. print(my_list)
  17. #print(my_sorted_list)
  18.        
  19. bubblesort(my_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement