뇌를 자극하는 알고리즘 질의응답 게시판입니다.
2010-07-30
by wiseheart
4210
void RBT_RebuildAfterRemove( RBTNode** Root, RBTNode* Successor )
{
RBTNode* Sibling = NULL;
while ( Successor->Parent != NULL && Successor->Color == BLACK)
{
if ( Successor == Successor->Parent->Left )
{
Sibling = Successor->Parent->Right;
if ( Sibling->Color == RED )
{
printf("Sibling(%d) Color is Red.\n", Sibling->Data);
Sibling->Color = BLACK;
Successor->Parent->Color = RED;
RBT_RotateLeft( Root, Successor->Parent );
/* 아래의 코드는 아무 의미가 없으므로 삭제합니다. */
/*Sibling = Successor->Parent->Right;*/
}
else
{
/* 기존의 내용과 동일합니다. */
}
}
else
{
Sibling = Successor->Parent->Left;
if ( Sibling->Color == RED )
{
printf("Sibling(%d) is RED.\n", Sibling->Data);
Sibling->Color = BLACK;
Successor->Parent->Color = RED;
RBT_RotateRight( Root, Successor->Parent );
/* 아래의 코드는 아무 의미가 없으므로 삭제합니다. */
/* Sibling = Successor->Parent->Left; */
}
else
{
/* 기존의 내용과 동일합니다. */
}
}
}
Successor->Color = BLACK;
}