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


Height balanced tree left rotation (Pascal version available)


tree lrot( t ) tree t; { tree temp; int a; temp = t; t = t->right; temp->right = t->left; t->left = temp; /*** adjust balance ***/ a = temp->bal; temp->bal = a - 1 - max( t->bal, 0 ); t->bal = min( a-2, min( a+t->bal-2, t->bal-1)); return( t ); }

C source (3413.lrot.c) Pascal source (3413.lrot.p)



© Addison-Wesley Publishing Co. Inc.