Advertisement
Guest User

sort

a guest
May 2nd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from random import shuffle
  3.  
  4. plt.ion()
  5.  
  6. def create_random_list(length):
  7.     some_list = [i for i in range(length)]
  8.     shuffle(some_list)
  9.     return some_list
  10.  
  11. def display(some_list):
  12.     plt.clf()
  13.     plt.bar(range(len(some_list)),some_list)
  14.     plt.draw()
  15.  
  16. def my_bubble_sort(some_list):
  17.     swapped = True
  18.     while swapped:
  19.         swapped = False
  20.         for i in range(len(some_list)-1):
  21.             if some_list[i] > some_list[i + 1]:
  22.                 some_list[i],some_list[i+1] = some_list[i + 1],some_list[i]
  23.                 swapped = True
  24.         display(some_list)
  25.  
  26.     return some_list
  27.  
  28. my_bubble_sort(create_random_list(100))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement