in reply to help! red-black binary tree problem

"here's the interesting part: at the end of my delete function, i return the successor node (referred to as $curr). if i have a receiver for the returned $curr node outside of my program, everything works fine."


Within RBDelete, you're telling $node's parent to point to $curr. $curr is local to RBDelete. If you don't store the-node-formerly-known-as-$curr outside the scope of RBDelete by capturing the return value, the parent of your deleted node will be pointing to undef.

  • Comment on Re: help! red-black binary tree problem

Replies are listed 'Best First'.
Re^2: help! red-black binary tree problem
by frustrated_intern (Initiate) on Jul 25, 2005 at 17:56 UTC
    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.