tankdthedruid

bubbleSort.py

Jul 3rd, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import random
  2.  
  3. N = 1000
  4. list1 = []
  5.  
  6. for i in range(0, N):
  7.     list1.append(random.randint(0, N-1))
  8.  
  9. list2 = list(list1)
  10. print '\nRandom Integer String:\n\n', list2
  11.  
  12. # Bubble Sort
  13. for i in range(0, len(list2) - 1):
  14.     swap_test = False
  15.     for j in range(0, len(list2) - i - 1):
  16.         if list2[j] > list2[j + 1]:
  17.             list2[j], list2[j + 1] = list2[j + 1], list2[j]
  18.         swap_test = True
  19.     if swap_test == False:
  20.         break
  21. print '\n\nSorted Integer String:\n\n', list2
Advertisement
Add Comment
Please, Sign In to add comment