SHARE
TWEET

buble_sort

Botontam May 23rd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. my_list= [5,9,5,8,1,3]
  2. unsorted= []
  3. old_list= my_list
  4.  
  5. def buble_sort (unsorted, old_list):
  6.     sorted = old_list [:]
  7.     for i in range (len(sorted)-1):
  8.         unsorted= (sorted, unsorted)
  9.        
  10.         if sorted [i] > unsorted [i+1]:
  11.             old_list= True
  12.            
  13.         else:
  14.             sorted [i], sorted [i+1]=sorted [i+1], sorted [i]
  15.             old_list=False
  16.             print (unsorted)
  17.     return buble_sort
  18.  
  19. new_list=buble_sort (old_list, my_list)
  20.  
  21. print (new_list)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top