Advertisement
timber101

ColinBubbleSort

Dec 27th, 2020
754
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data Copied
Advertisement