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


List merging


function merge ( a, b : list ) : list; var first, last, temp : list; begin first := nil; while b <> nil do if a = nil then begin a := b; b := nil end else begin if b^.k > a^.k then begin temp := a; a := a^.next end else begin temp := b; b := b^.next end; temp^.next := nil; tailins( temp, first, last ) end; tailins( a, first, last ); merge := first end;

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



© Addison-Wesley Publishing Co. Inc.