|
of_balanceright
|
|
Full name
|
pfc_n_cst_tree.of_balanceright
|
Access
|
protected
|
Extend of
|
integer
|
Return value
|
integer
|
Prototype
|
protected function integer of_balanceright(ref n_cst_treenode,ref boolean)
|
Name
|
Datatype
|
li_b1
|
integer
|
li_b2
|
integer
|
lnv_pivot1
|
n_cst_treenode
|
lnv_pivot2
|
n_cst_treenode
|
lnv_temp
|
n_cst_treenode
|
protected function integer of_balanceright (ref n_cst_treenode anv_currentnode, ref boolean ab_height);//////////////////////////////////////////////////////////////////////////////
//
// Function: of_balanceright
//
// Access: protected
//
// Arguments :
// anv_currentnode n_cst_treenode : node to be balanced
// ab_height boolean : indicates whether the 'height; of the tree has changed or not
//
// Returns: integer
// 1 : success (always)
//
// Description: Balances the right side of a node
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
// 6.0 Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1996-1997 Sybase, Inc. and its subsidiaries. All rights reserved.
// Any distribution of the PowerBuilder Foundation Classes (PFC)
// source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////
n_cst_treenode lnv_pivot1,lnv_pivot2,lnv_temp
integer li_b1,li_b2
choose case anv_currentnode.of_getbalance() // right branch has become less high
case 1
anv_currentnode.of_setbalance(0)
case 0
anv_currentnode.of_setbalance(-1)
ab_height = false
case -1 // rebalance
anv_currentnode.of_getprev(lnv_pivot1)
li_b1 = lnv_pivot1.of_getbalance()
if li_b1 <= 0 then // single LL rotation
lnv_pivot1.of_getnext(lnv_temp)
anv_currentnode.of_setprev(lnv_temp)
lnv_pivot1.of_setnext(anv_currentnode)
if li_b1 = 0 then
anv_currentnode.of_setbalance(-1)
lnv_pivot1.of_setbalance(1)
ab_height = false
else
anv_currentnode.of_setbalance(0)
lnv_pivot1.of_setbalance(0)
end if
anv_currentnode = lnv_pivot1
else // double LR rotation
lnv_pivot1.of_getnext(lnv_pivot2)
li_b2 = lnv_pivot2.of_getbalance()
lnv_pivot2.of_getprev(lnv_temp)
lnv_pivot1.of_setnext(lnv_temp)
lnv_pivot2.of_setprev(lnv_pivot1)
lnv_pivot2.of_getnext(lnv_temp)
anv_currentnode.of_setprev(lnv_temp)
lnv_pivot2.of_setnext(anv_currentnode)
if li_b2 = -1 then
anv_currentnode.of_setbalance(1)
else
anv_currentnode.of_setbalance(0)
end if
if li_b2 = 1 then
lnv_pivot1.of_setbalance(-1)
else
lnv_pivot1.of_setbalance(0)
end if
anv_currentnode = lnv_pivot2
lnv_pivot2.of_setbalance(0)
end if
end choose
return 1
end function