[Home]
[Chapter]
[Contents]
[Previous Algorithm]
[Next Algorithm]


Merging of arrays


procedure merge ( a,b : RecordArray; var c : RecordArray; na,nb : integer ); {*** Merges the arrays a and b into c (increasing order assumed) a or b may coincide with c ***} begin while (na>=1) or (nb>=1) do if na<1 then while nb>0 do begin c[nb] := b[nb]; nb := nb-1 end {while} else if nb<1 then while na>0 do begin c[na] := a[na]; na := na-1 end {while} else if a[na].k < b[nb].k then begin c[na+nb] := b[nb]; nb := nb-1 end {if...then} else begin c[na+nb] := a[na]; na := na-1 end; {else} end;

C source (432.merge.c) Pascal source (432.merge.p)



© Addison-Wesley Publishing Co. Inc.