The Most Active and Friendliest
Affiliate Marketing Community Online!

“AdsEmpire”/  Direct Affiliate

Merge Sort

istanbul

New Member
affiliate
PHP:
program merge_sort;
uses wincrt;
var
a,b,c:array [1..100] of integer;
n,m,i,j,k,t:integer;
begin
write('number of a and b in order >>> ');
read(n,m);writeln;
for i:=1 to n do
read(a[i]);
writeln;
for j:=1 to m do
read(b[j]);
i:=1;j:=1;k:=1;
while ((i<=n) and (j <= m)  ) do begin
if ( a[i]> b[j]) then begin
c[k]:= b[j]; j:=j+1 end else
begin c[k]:= a[i]; i:=i+1 end; k:=k+1 end;
if (i>n) then begin for t:=i to m do begin c[k]:= b[t];k:=k+1 end end
else begin for t:=j to n do begin c[k]:= a[t]; k:=k+1 end end;
for k:=1 to n+m do
write(c[k]:4)
end.

From my library...
 
MI
Back