Code : Tout sélectionner
def tri_insertion(l):
for i in range (len(l)):
aux = l[i]
k = i
while k >= 1 and aux < l[k-1] > aux:
l[k] = l[k-1]
k = k-1
l[k] = aux
L = [1, 3, 2]
tri_insertion(L)
def tri_selection(l):
for i in range(len(l)):
mini = i
for j in range(i+1, len(l)):
if l[mini] > l[j]:
mini = j
tmp = l[i]
l[i] = l[mini]
l[mini] = tmp
L = [4, 9, 7, 2 ,3]
tri_selection(L)