1
Thanks

A few words of thanks would be greatly appreciated.

Pascal - Sort by merging- recursion





Here is a recursive procedure which can sort an array of n integers using the method of Merge sort

Procedure Sort_Merge (Var t : TAB; g, d : integer); 
Var
m, i, j, k : integer;
s : TAB;
Begin
If d > g Then
Begin
m := (g + d) Div 2;
Sort_Merge (t, g, m);
Sort_Merge (t, m + 1, d);

For i := m DownTo g Do
s[i] := t[i];

For j := m + 1 To d Do
s[d + m + 1 - j] := t[j];

i := g; j := d;
For k := g To d Do
Begin
If s[i] < s[j] Then
Begin
t[k] := s[i];
i := i + 1;
End
Else
Begin
t[k] := s[j];
j := j - 1;
End;
End;
End;
End;



Thanks to Zouari Lazhar for this tip.
1
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

This document, titled « Pascal - Sort by merging- recursion », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

0 Comments