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


P-tree insertion


procedure insert ( new : tree; var pq : tree ); label 9999; var p : tree; begin if pq = nil then pq := new else if pq^.k >= new^.k then begin {*** Insert above subtree ***} new^.left := pq; pq := new end else begin p := pq; while p^.left <> nil do if p^.left^.k >= new^.k then begin {*** Insert in right subtree ***} insert( new, p^.right ); goto 9999 end else p := p^.left; {*** Insert at bottom left ***} p^.left := new end; 9999: end;

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



© Addison-Wesley Publishing Co. Inc.