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


Weight balanced tree insertion


procedure insert( key : typekey; var t : tree ); begin if t = nil then begin t := NewNode( key, nil, nil ); t^.weight := 2 end else if t^.k = key then Error {*** Key already in table ***} else with t^ do begin if k < key then insert( key, right ) else insert( key, left ); weight := wt( left ) + wt( right ); checkrots( t ) end end;

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



© Addison-Wesley Publishing Co. Inc.