Algorithme de tri

Forum Lycée Carnot


Répondre
Avatar du membre
maths-code
Site Admin
Messages : 40
Enregistré le : mer. avr. 19, 2023 9:02 pm

Algorithme de tri

Message par maths-code »

Code : Tout sélectionner

def tri_insertion(l):
    for i in range (len(l)):
        aux = l[i]
        k = i
        while k >= 1 and aux < l[k-1] > aux:
            l[k] = l[k-1]
            k = k-1
            l[k] = aux
L = [1, 3, 2]
tri_insertion(L)

def tri_selection(l):
   for i in range(len(l)):
       mini = i
       for j in range(i+1, len(l)):
           if l[mini] > l[j]:
               mini = j 
       tmp = l[i]
       l[i] = l[mini]
       l[mini] = tmp
L = [4, 9, 7, 2 ,3]
tri_selection(L)

Répondre