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


Sorted list insertion


procedure insert( new : list; var pq : list ); label 9999; var p : list; begin if pq=nil then pq := new else if pq^.k < new^.k then begin new^.next := pq; pq := new end else begin p := pq; while p^.next <> nil do begin if p^.next^.k < new^.k then begin new^.next := p^.next; p^.next := new; goto 9999 end; p := p^.next end; p^.next := new end; 9999: end;

C source (511.ins.c) Pascal source (511.ins.p)



© Addison-Wesley Publishing Co. Inc.