tankdthedruid

insertionSort.py

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