设为首页 加入收藏

TOP

删除功能更加完备的红黑树(二)
2014-11-24 00:04:17 来源: 作者: 【 】 浏览:76
Tags:删除 功能 更加 完备
tmp=parent;

parent=curnode;

curnode=tmp;

curnode->m_color=BLACK;

rotate_left (grandparent ,parent );

curnode=parent;

parent=curnode->parent;

if(!parent )

{

node->root=curnode;

break;

}

}

}

else

{

if ( parent== grandparent->right)

{

curnode->m_color=BLACK;

rotate_left (grandparent,parent );

curnode=parent;

parent=curnode->parent;

if(!parent )

{

node->root=curnode;

break;

}

}

else

{

// printf("nothing");

rotate_left ( parent ,curnode);

tmp=parent;

parent=curnode;

curnode=tmp;

curnode->m_color=BLACK;

rotate_right (parent,grandparent );

curnode=parent;

parent=curnode->parent;

if(!parent )

{

node->root=curnode;

break;

}

}

}

}

}

redblack * find(redblack *root ,int data)

{

if (! root)

{

return NULL;

}

else

{

if ( data == root->m_data->value)

{

return root;

}

else if ( data > root->m_data->value )

{

return find (root ->right ,data);

}

else

{

return find (root->left ,data );

}

}

}

redblack * next (redblack * mostleft)

{

// if

if(! mostleft->left)

{

return mostleft;

}

else

{

return next ( mostleft->left);

}

}

void delete_fixup (wrapdata *node, redblack *curnode ,int mode)

{

redblack *parent;

redblack *uncle;

redblack *uncle_left;

redblack *uncle_right;

while(1)

{

if (curnode->m_color==RED)

{

curnode->m_color=BLACK;

parent=curnode->parent;

if(!parent)

{

node->root=curnode;

}

return ;

}

else www.2cto.com

{

parent=curnode->parent;

if(!parent)

{

node->root=curnode;

return ;

}

if(0==mode)

{

uncle=parent->right;

if(!uncle)

{

return ;

}

if (uncle->m_color== RED)

{

uncle->m_color=BLACK;

parent->m_color=RED;

rotate_left (parent,uncle );

}

else

{

uncle_left=uncle->left;

uncle_right=uncle->right;

if( (!uncle_left || uncle_left->m_color==BLACK )

&&

(!uncle_right || uncle_right->m_color==BLACK))

{

uncle->m_color=RED;

curnode=parent;

}

else

{

if( !uncle_right || uncle_right->m_color==RED)

{

uncle->m_color=parent->m_color;

parent->m_color=BLACK;

uncle_right->m_color=BLACK;

rotate_left( parent,uncle);

curnode=uncle;

}

}

}

}

else

{

uncle=parent->left;

if(!uncle)

{

return ;

}

if (uncle->m_color== RED)

{

uncle->m_color=BLACK;

parent->m_color=RED;

rotate_right (uncle ,parent);

}

else

{

uncle_left=uncle->left;

uncle_right=uncle->right;

if( (!uncle_left || uncle_left->m_color==BLACK )

&&

(!uncle_right || uncle_right->m_color==BLACK))

{

uncle->m_color=RED;

curnode=parent;

}

else

{

if( !uncle_left || uncle_left->m_color==RED)

首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇在高警告级别干净利落的进行编译 下一篇相对完整的红黑树(经过比较强的测..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: