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


Leftist trees distance


function distance( pq : tree ) : integer; begin if pq=nil then distance := 0 else distance := pq^.dist end; procedure fixdist( pq : tree ); var temp : tree; begin if distance(pq^.left) < distance(pq^.right) then begin temp := pq^.right; pq^.right := pq^.left; pq^.left := temp end; pq^.dist := distance(pq^.right) + 1 end;

C source (516.dist.c) Pascal source (516.dist.p)



© Addison-Wesley Publishing Co. Inc.