Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Prochaine révision Les deux révisions suivantes | ||
les_programmes_a_connaitre:algorithmique_premiere:tri_selection [2021/01/26 10:55] rd |
les_programmes_a_connaitre:algorithmique_premiere:tri_selection [2022/03/25 11:54] cl |
||
---|---|---|---|
Ligne 8: | Ligne 8: | ||
{{: | {{: | ||
<code python> | <code python> | ||
- | i=1 | + | # -*- coding: utf-8 -*- |
- | while i<len(t): | + | """ |
- | | + | Fiche de Révision - Trie par sélection |
- | mini=i | + | """ |
- | | + | |
- | if t[j]<t[mini]: | + | # Intialisation de Variable |
- | mini=j | + | tab = [98, 22, 15, 32, 2, 74, 63, 70] |
- | j=j+1 | + | # Fin Initialisation de Variable |
- | if mini!=i: | + | |
- | | + | # Fonction |
- | i=i+1 | + | """ |
+ | Entrée : tab : tableau/ | ||
+ | Sortie : tab : tableau/ | ||
+ | Objectif : Trié le tableau tab, avec la méthode par sélection | ||
+ | """ | ||
+ | |||
+ | def tri_selection(tab): | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | min = j # Décalage | ||
+ | |||
+ | k = tab[i] # Décalage | ||
+ | tab[i] = tab[min] # Décalage | ||
+ | tab[min] | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | #Fin Fonction | ||
+ | |||
+ | # Programme Principal | ||
+ | print(tab) # Intialisation | ||
+ | print(tri_selection(tab)) # Lancement de Variable | ||
</ | </ | ||
{{ : | {{ : | ||
- | La méthode par __sélection__ | + | La méthode par __sélection__ |