tri_selection.py

Created by vincent-labbe

Created on June 21, 2018

276 Bytes

Définit une fonction qui affiche les étapes du tri par sélection d’une liste (sans modifier cette liste).


def triSel(l):
 L=l.copy()
 print(L)
 print("Etapes:")
 nb=0
 for i in range(0,len(L)-1):
  k=i
  for j in range(i+1,len(L)):
   if L[j]<L[k] :
    k=j
   nb+=1
  temp=L[i]
  L[i]=L[k]
  L[k]=temp
  print(L)
 print(nb, "comparaisons.")
triSel([6,5,8,3,2])