Algorithme complet
O(n²)À chaque étape : minimum de la partie droite, puis échange.
for indice in range(nb-1)Partie non triée
indice_min = indiceCandidat minimum
tableau[j] < tableau[indice_min]Chercher à droite
Échange
Si indice_min ≠ indice
def tri_selection(tableau):
nb_elements = len(tableau)
for indice in range(0, nb_elements - 1):
indice_min = indice
for suivant in range(indice + 1, nb_elements):
if tableau[suivant] < tableau[indice_min]:
indice_min = suivant
if indice_min != indice:
tableau[indice], tableau[indice_min] = (
tableau[indice_min], tableau[indice]
)