Guest User

Bubble sort (most simple)

a guest
Jul 21st, 2010
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. '''
  2. Created on 21.07.2010
  3.  
  4. @author: chaporgin_a
  5. '''
  6. a = [1,2,1,5,4,5]
  7. print(a)
  8. n = len(a)
  9. buff = None
  10. k = 0
  11. while k < n:
  12.     t = k
  13.     while t < n-1:
  14.         if a[t] > a[t+1]:
  15.             buff = a[t+1]
  16.             a[t+1] = a[t]
  17.             a[t] = buff
  18.         t += 1
  19.     k+=1
  20. print(a)
Advertisement
Add Comment
Please, Sign In to add comment