[Pascal]TRI SHELL -Recursion
Tri Shell Recursion
Below is a recursive process that allows sorting n integers using Tri Shell.
Procedure Tri_Shell_Rec (Var t: TAB; n,h : integer);
Var aux,i : integer;
begin If h > 0 Then
Begin
If n > h Then
begin
Tri_Shell_Rec (t,n - h,h);
If t[n] < t[n - h] Then
Begin
aux:= t[n];
i := n;
Repeat
t[i] := t[i - h];
i := i - h;
Until (i = h) Or (aux > t[i - h]);
t[i] := aux;
End;
End;
Tri_Shell_Rec (t,n,h Div 3);
End;
End;<
Note:
It is recommended to test this procedure on small tables as if this is not the case and the number of calls become important and will however cause a spillover the battery. The technique for recursion is the memory.
We can increase the table test size by augmenting the battery size.