Advertisement
infnetdanpro

Bubble sort

Sep 23rd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. #-*-coding:utf8;-*-
  2. #qpy:3
  3. #qpy:console
  4.  
  5. #On^2
  6. from time import sleep
  7.  
  8. def bubble_sort(l):
  9.     swap = True
  10.     while swap:
  11.         swap = False
  12.         for i in range(len(l)-1):
  13.             if l[i] > l[i+1]:
  14.                 l[i], l[i+1] = l[i+1], l[i]
  15.                 swap = True
  16.  
  17.  
  18. list_ = [5, 2, 1, 8, 4, 70, 44]
  19. bubble_sort(list_)
  20. print(list_)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement