Frédéric Léon -- MATHS -- E. Brontë

D'après un exemple sur le site d'AlgoBox.

max (ici 7) entiers relatifs sont générés dans l'intervalle [-10;10[, l'algorithme permet de trier la liste dans l'ordre croissant en comparant les entiers côte à côte et en changeant leur place si besoin.

pour modifier l'intervalle et/ou la nature des nombres, il faut changer la formule de la ligne 13

AlgoBox : Tri à bulles avec affichage intermédiaire des résultats.
Tester l'algorithme
Cliquer sur ce bouton pour exécuter l'algorithme : 

Résultats

Code de l'algorithme
1   VARIABLES
2     listeatrier EST_DU_TYPE LISTE
3     i EST_DU_TYPE NOMBRE
4     j EST_DU_TYPE NOMBRE
5     temp EST_DU_TYPE NOMBRE
6     k EST_DU_TYPE NOMBRE
7     max EST_DU_TYPE NOMBRE
8   DEBUT_ALGORITHME
9     max PREND_LA_VALEUR 7
10    AFFICHER "Avant le tri :"
11    POUR i ALLANT_DE 1 A max
12      DEBUT_POUR
13      listeatrier[i] PREND_LA_VALEUR floor(random()*20-10)
14      AFFICHER listeatrier[i]
15      AFFICHER " "
16      FIN_POUR
17    AFFICHER " "
18    AFFICHER "étapes de tri"
19    POUR i ALLANT_DE 1 A max-1
20      DEBUT_POUR
21      POUR j ALLANT_DE 1 A max-1
22        DEBUT_POUR
23        SI (listeatrier[j+1]<listeatrier[j]) ALORS
24          DEBUT_SI
25          temp PREND_LA_VALEUR listeatrier[j]
26          listeatrier[j] PREND_LA_VALEUR listeatrier[j+1]
27          listeatrier[j+1] PREND_LA_VALEUR temp
28          FIN_SI
29        POUR k ALLANT_DE 1 A max
30          DEBUT_POUR
31          AFFICHER listeatrier[k]
32          AFFICHER " "
33          FIN_POUR
34        AFFICHER " "
35        FIN_POUR
36      FIN_POUR
37  FIN_ALGORITHME