Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- L=[]
- for i in range(randint(5, 15)):
- L.append(randint(0, 20))
- print(L)
- def insertionSort(L, n):
- if n > 0:
- insertionSort(L, n-1)
- a = L[n]
- i = n-1
- while i >= 0 and L[i] > a:
- L[i+1] = L[i]
- i -= 1
- L[i+1] = a
- insertionSort(L, len(L)-1)
- print(L)
- from random import randint
- L=[]
- for i in range(randint(5, 15)):
- L.append(randint(0, 20))
- print(L)
- def selectionSort(L):
- temp = L[0]
- n = 0
- if len(L) > 1:
- for i in range(1, len(L)):
- if L[i] < temp:
- temp = L[i]
- n=i
- del L[n]
- return [temp] + selectionSort(L)
- else:
- return L
- print(selectionSort(L))
Add Comment
Please, Sign In to add comment