Hola ,
voila , je veux transformer ce tri d'insertion en un tri d'insertion récursif or je ne suis pas très fort en récursivité de l'aide sera la bienvenue
Voila mon essai
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 procedure tri_insertion(n : integer ; var t : tab ); var x :integer ; begin for i:= 2 to n do begin j:=i ; while (t[j] <t[j-1]) and (j > 1) do begin x:=t[j] ; t[j]:=t[j-1]; t[j-1]:=x; j:=j-1 ; end; end; end;
remarque : à l'initialisation dans le programme principal
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 procedure tri_insertion(n : integer ; var t : tab ; i : integer); var x : integer ; begin if (i >= 2) and (i <= n) then begin j:=i ; while (t[j] <t[j-1]) and (j > 1) do begin x:=t[j] ; t[j]:=t[j-1]; t[j-1]:=x; j:=j-1 ; end; tri_insertion(n,t,i+1); end; end;
i sera remplacer par 2.
tri_insertion(n,t,2);
Merci d'avance pour votre réponse.
Partager