本文整理汇总了C++中AVLTree::RestoreBalances方法的典型用法代码示例。如果您正苦于以下问题:C++ AVLTree::RestoreBalances方法的具体用法?C++ AVLTree::RestoreBalances怎么用?C++ AVLTree::RestoreBalances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AVLTree
的用法示例。
在下文中一共展示了AVLTree::RestoreBalances方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Remove
/*
* removal
*/
int
AVLTree::Remove (AVLTree * &racine, bool rebalance)
{
AVLTree *startNode = NULL;
int remDiff = 0;
int res = Remove (racine, startNode, remDiff);
if (res == avl_no_err && rebalance && startNode)
res = startNode->RestoreBalances (remDiff, racine);
return res;
}
示例2: if
int
AVLTree::RestoreBalances (int diff, AVLTree * &racine)
{
if (balance > 0)
{
if (diff < 0)
{
balance = 0;
if (parent)
{
if (this == parent->child[RIGHT])
return parent->RestoreBalances (1, racine);
if (this == parent->child[LEFT])
return parent->RestoreBalances (-1, racine);
}
return avl_no_err;
}
else if (diff == 0)
{
}
else if (diff > 0)
{
if (child[LEFT] == NULL)
{
// cout << "un probleme\n";
return avl_bal_err;
}
AVLTree *r = parent;
AVLTree *a = this;
AVLTree *b = child[RIGHT];
AVLTree *e = child[LEFT];
AVLTree *f = e->child[RIGHT];
AVLTree *g = e->child[LEFT];
if (e->balance > 0)
{
e->child[RIGHT] = a;
e->child[LEFT] = g;
a->child[RIGHT] = b;
a->child[LEFT] = f;
if (a)
a->parent = e;
if (g)
g->parent = e;
if (b)
b->parent = a;
if (f)
f->parent = a;
e->parent = r;
if (r)
{
if (r->child[LEFT] == a)
r->child[LEFT] = e;
if (r->child[RIGHT] == a)
r->child[RIGHT] = e;
}
if (racine == this)
racine = e;
e->balance = 0;
a->balance = 0;
if (r)
{
if (e == r->child[RIGHT])
return r->RestoreBalances (1, racine);
if (e == r->child[LEFT])
return r->RestoreBalances (-1, racine);
}
return avl_no_err;
}
else if (e->balance == 0)
{
e->child[RIGHT] = a;
e->child[LEFT] = g;
a->child[RIGHT] = b;
a->child[LEFT] = f;
if (a)
a->parent = e;
if (g)
g->parent = e;
if (b)
b->parent = a;
if (f)
f->parent = a;
e->parent = r;
if (r)
{
if (r->child[LEFT] == a)
r->child[LEFT] = e;
if (r->child[RIGHT] == a)
r->child[RIGHT] = e;
}
if (racine == this)
racine = e;
e->balance = -1;
a->balance = 1;
return avl_no_err;
}
else if (e->balance < 0)
{
if (child[LEFT]->child[RIGHT] == NULL)
{
//.........这里部分代码省略.........