Unsorted list extraction


function extract( var pq : list ) : typekey; var max, p : list; begin if pq=nil then Error {*** Extraction from an empty list ***} else if pq^.next = nil then begin extract := pq^.k; pq := nil end else begin max := pq; p := pq; while p^.next <> nil do begin if max^.next^.k < p^.next^.k then max := p; p := p^.next end; if max^.next^.k < pq^.k then begin extract := pq^.k; pq := pq^.next end else begin extract := max^.next^.k; max^.next := max^.next^.next end end end;

Pascal source (511b.extr.p)



© Addison-Wesley Publishing Co. Inc.