-2
這是修復紅黑樹的函數,但編譯器一直給出l值必須是可修改的,while循環條件中的'z'導致問題(z!=根)時,而應r.un直到Z指針是指向特定鍵達到「z」的指針指向l值必須是可修改的錯誤
void Tree::fixup(int z)
{
fixuppri(root, z);
}
void Tree::fixuppri(node* root, int a)
{
node* z ;
z = returnnode(a);
while (z != root && z->parent->color = 'r')
{
node* y;
if (z->parent == z->parent->parent->left)
{
y = z->parent->parent->right;
}
else
{
y = z->parent->parent->left;
}
if (y->color = 'r')
{
z->parent->parent->color = 'r';
z->parent->color = 'b';
y->color = 'b';
z = z->parent->parent;
}
else
{
if (z->parent == z->parent->parent->left && z == z->parent->left)
{
char tempcolor = z->parent->color;
z->parent->color = z->parent->parent->color;
z->parent->parent->color = tempcolor;
rightrotate(z->parent->parent);
}
if (z->parent == z->parent->parent->left && z == z->parent->right)
{
char tempcolor = z->color;
z->color = z->parent->parent->color;
z->parent->parent->color = tempcolor;
leftrotate(z->parent);
rightrotate(z->parent->parent);
}
if (z->parent == z->parent->parent->right && z == z->parent->right)
{
char tempcolor = z->parent->color;
z->parent->color = z->parent->parent->color;
z->parent->parent->color = tempcolor;
leftrotate(z->parent->parent);
}
if (z->parent == z->parent->parent->right && z == z->parent->left)
{
char tempcolor = z->color;
z->color = z->parent->parent->color;
z->parent->parent->color = tempcolor;
rightrotate(z->parent);
leftrotate(z->parent->parent);
}
}
}
root->color = 'b';
}
'z-> parent-> color ='r''你是不是指'=='?還有一個更進一步。也許你應該看看RB樹之前的基本語法。 – user657267 2014-10-03 10:27:14
哦,夥計,這是問題 – 2014-10-03 10:49:05
喲,它走了,謝謝 – 2014-10-03 10:50:24