I realize that the problem has to do with scoping -- however, the problem doesn't have to do with the parent of the deleted node pointing to undef. Each node has three pointers: pointer to parent, and pointer to children(left/right).
If I'm dealing with the case that both $node and $curr point to the same RBNode (see code in previous post). The strange thing that happens is that the deleted node's children's parent pointers end up pointing to undef, even though $curr's parent's left and right pointers point to the proper nodes. I find this baffling. Any ideas as to how to fix the problem?
The catch with my RedBlack binary tree implementation is that I can't capture any return balue. Any ideas as to how to fix my code w/o having to capture any return value? The code works perfectly fine when $node and $curr point to distinct nodes.
Thanks. |