Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bubble(L):
- cnt = 0
- for i in range(len(L)):
- for j in range(len(L)-1):
- if L[j] > L[j+1]:
- L[j], L[j+1] = L[j+1], L[j]
- cnt += 1
- print("cnt: ", cnt)
- return(L)
- def bubble_ex(alst):
- swap = True
- cnt = 0
- while swap:
- swap = False
- for i in range(len(alst)-1):
- if alst[i] > alst[i+1]:
- alst[i], alst[i+1] = alst[i+1], alst[i]
- swap = True
- cnt += 1
- print("cnt:",cnt)
- return alst
- import random
- print(bubble_ex([random.randint(1, 50) for _ in range(65)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement