Guest User

Untitled

a guest
Feb 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. from random import randint
  2. L=[]
  3. for i in range(randint(5, 15)):
  4. L.append(randint(0, 20))
  5. print(L)
  6.  
  7. def insertionSort(L, n):
  8. if n > 0:
  9. insertionSort(L, n-1)
  10. a = L[n]
  11. i = n-1
  12. while i >= 0 and L[i] > a:
  13. L[i+1] = L[i]
  14. i -= 1
  15. L[i+1] = a
  16.  
  17.  
  18. insertionSort(L, len(L)-1)
  19. print(L)
  20.  
  21. from random import randint
  22. L=[]
  23. for i in range(randint(5, 15)):
  24. L.append(randint(0, 20))
  25. print(L)
  26.  
  27. def selectionSort(L):
  28. temp = L[0]
  29. n = 0
  30. if len(L) > 1:
  31. for i in range(1, len(L)):
  32. if L[i] < temp:
  33. temp = L[i]
  34. n=i
  35. del L[n]
  36. return [temp] + selectionSort(L)
  37. else:
  38. return L
  39.  
  40.  
  41. print(selectionSort(L))
Add Comment
Please, Sign In to add comment