PEP-huître
This commit is contained in:
parent
e398faa3dc
commit
5a63207ef6
|
@ -82,6 +82,7 @@ def tri_selection(l):
|
|||
imin = select_min(l, i, n - 1)
|
||||
l[i], l[imin] = l[imin], l[i]
|
||||
|
||||
|
||||
def tri_insertion_base(l, n):
|
||||
"""
|
||||
list, int → ∅
|
||||
|
@ -89,17 +90,18 @@ def tri_insertion_base(l, n):
|
|||
CU: n est un entier < len(l) et l est une liste, dont les éléments sont comparables, triée jusqu'à l'indice n-1.
|
||||
"""
|
||||
|
||||
assert(type(n)==int and type(l)==list and n < len(l))
|
||||
assert(type(n) == int and type(l) == list and n < len(l))
|
||||
|
||||
aux = l[n]
|
||||
|
||||
k=n
|
||||
while k >= 1 and comp(l[k-1], aux)== 1:
|
||||
l[k] = l[k-1]
|
||||
k = n
|
||||
while k >= 1 and comp(l[k - 1], aux) == 1:
|
||||
l[k] = l[k - 1]
|
||||
k -= 1
|
||||
|
||||
l[k] = aux
|
||||
|
||||
|
||||
def tri_insertion(l):
|
||||
for i in range(1, len(l)):
|
||||
tri_insertion_base(l, i)
|
||||
|
@ -183,7 +185,7 @@ partie("Analyse du tri par sélection")
|
|||
question(1)
|
||||
|
||||
for i in range(2, 102):
|
||||
print(i-1, " ", tri_et_compte(tri_selection, liste_croissante(i))[1], " ", tri_et_compte(
|
||||
print(i - 1, " ", tri_et_compte(tri_selection, liste_croissante(i))[1], " ", tri_et_compte(
|
||||
tri_selection, liste_alea(i, 0, 500))[1], " ", tri_et_compte(tri_selection, liste_decroissante(i))[1])
|
||||
|
||||
question(2)
|
||||
|
@ -193,7 +195,7 @@ partie("Analyse du tri par insertion")
|
|||
question(1)
|
||||
|
||||
for i in range(2, 102):
|
||||
print(i-1, " ", tri_et_compte(tri_insertion, liste_croissante(i))[1], " ", tri_et_compte(
|
||||
print(i - 1, " ", tri_et_compte(tri_insertion, liste_croissante(i))[1], " ", tri_et_compte(
|
||||
tri_insertion, liste_alea(i, 0, 500))[1], " ", tri_et_compte(tri_insertion, liste_decroissante(i))[1])
|
||||
|
||||
section("Dans le meilleur des cas")
|
||||
|
|
Reference in a new issue