Binary Search Tree node removal

Posted by doc on Stack Overflow See other posts from Stack Overflow or by doc
Published on 2010-04-04T09:35:48Z Indexed on 2010/04/04 9:43 UTC
Read the original article Hit count: 315

Filed under:
|

I've been trying to implement a delete function for a Binary Search Tree but haven't been able to get it to work in all cases.

This is my latest attempt:

if(t->get_left() == empty)
 *t = *t->get_left();
else if(t->get_right() == empty)
 *t = *t->get_right();
else if((t->get_left() != empty) && (t->get_right() != empty))
{
 Node* node = new Node(t->get_data(), t->get_parent(), t->get_colour(), t->get_left(), t->get_right());
 *t = *node;
}

t is a node and empty is just a node with nothing in it.

I'm just trying to swap the values but I'm getting a runtime error. Any ideas?

Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about binary-trees