Advertisement
zhongnaomi

my bubble sort def

Feb 12th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. from random import randint
  2.  
  3. list_to_sort = [randint(1,100) for i in range(33)]
  4. print(list_to_sort)
  5.  
  6. def mbubble_sort(sorted):
  7.     n = len(sorted)  
  8.     while (n >= 1 ) :
  9.         newn = 0
  10.         for i in range(1, len(sorted)):
  11.             if sorted[i-1] > sorted[i]:
  12.                 sorted[i-1], sorted[i] = sorted[i], sorted[i-1]
  13.                 newn = i
  14.         n = newn
  15.     return sorted
  16.  
  17. mbubble_sort(list_to_sort)
  18. print(list_to_sort)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement