"'O
0
c
:J
0
li)
..--t
0
N
@
.......
J::
O'l
·;::::
>0.
0
u
Chapitre l 0 · Travaux pratiques
244
1
Ajouter x à petits
Sinon
1
Ajouter x à grands
Fin Si
Retourner(tri_rapide(petits)+[pivot]+tri_rapide(grands))
Fin Fonction
.. . ... . ... . ... . .. .. .. . . Partie principale ... . ... . .. . ... . ....... . .. . .
Début
Lh +--- []
Pour k de 0 à 99 Faire
#génère une liste de l OO réels au hasard
1 Ajouter random.random() à Lh
Fin Pour
debut +--- time.time()
tri_select(Lh)
fin +--- time.time()
Afficher 'Temps d'exécution en secondes avec le tri par sélection : ",fin-debut
Lh +--- []
Pour k de 0 à 99 Faire
1
Ajouter random.random() à Lh
Fin Pour
debut +--- time.time()
tri_bu l les(Lh)
fin +--- time .time()
Afficher 'Temps d'ex écution en secondes avec le tri à bulles : ",fin-debut
Lh +--- []
Pour k de 0 à 99 Faire
1
Ajouter random.random() à Lh
Fin Pour
debut +--- time.tim e()
tri_rapide(Lh)
fin +--- time.time()
Afficher 'Temps d'ex écution en secondes avec le tri rapide : ",fin-debut
Fin
b) Implémentation Python
######################### F o n c ti o ns #############################
def tri _ se l ec t ( L) :
fo r i in r a nge( O, l e n ( L) -1 ):
f o r j in r a n ge( i + l , len (L)) :
i f L[ j ]
L[ i ] , L[ j ] =L[ j ] , L[ i ]
r et urn ( L)
def t r i _ bull e s (L):
ec h a n g e = Tr u e
\\h i l e ec h a nge == Tru e:
ec h a n ge = Fa l s e
fo r i in ra n ge(O, l e n (L) -1 ):
i f L[ i ] >L[ i + L] :
r e t u r n ( L)
L[ i ] , L[ i + l] =L[ i + 1] , L[ i ]
ec h a n ge = Tr u e
0
c
:J
0
li)
..--t
0
N
@
.......
J::
O'l
·;::::
>0.
0
u
Chapitre l 0 · Travaux pratiques
244
1
Ajouter x à petits
Sinon
1
Ajouter x à grands
Fin Si
Retourner(tri_rapide(petits)+[pivot]+tri_rapide(grands))
Fin Fonction
.. . ... . ... . ... . .. .. .. . . Partie principale ... . ... . .. . ... . ....... . .. . .
Début
Lh +--- []
Pour k de 0 à 99 Faire
#génère une liste de l OO réels au hasard
1 Ajouter random.random() à Lh
Fin Pour
debut +--- time.time()
tri_select(Lh)
fin +--- time.time()
Afficher 'Temps d'exécution en secondes avec le tri par sélection : ",fin-debut
Lh +--- []
Pour k de 0 à 99 Faire
1
Ajouter random.random() à Lh
Fin Pour
debut +--- time.time()
tri_bu l les(Lh)
fin +--- time .time()
Afficher 'Temps d'ex écution en secondes avec le tri à bulles : ",fin-debut
Lh +--- []
Pour k de 0 à 99 Faire
1
Ajouter random.random() à Lh
Fin Pour
debut +--- time.tim e()
tri_rapide(Lh)
fin +--- time.time()
Afficher 'Temps d'ex écution en secondes avec le tri rapide : ",fin-debut
Fin
b) Implémentation Python
######################### F o n c ti o ns #############################
def tri _ se l ec t ( L) :
fo r i in r a nge( O, l e n ( L) -1 ):
f o r j in r a n ge( i + l , len (L)) :
i f L[ j ]
r et urn ( L)
def t r i _ bull e s (L):
ec h a n g e = Tr u e
\\h i l e ec h a nge == Tru e:
ec h a n ge = Fa l s e
fo r i in ra n ge(O, l e n (L) -1 ):
i f L[ i ] >L[ i + L] :
r e t u r n ( L)
L[ i ] , L[ i + l] =L[ i + 1] , L[ i ]
ec h a n ge = Tr u e
