Perl Monk, Perl Meditation | |
PerlMonks |
help! red-black binary tree problemby frustrated_intern (Initiate) |
on Jul 23, 2005 at 00:41 UTC ( [id://477400]=perlquestion: print w/replies, xml ) | Need Help?? |
frustrated_intern has asked for the wisdom of the Perl Monks concerning the following question:
hi,
i'm a relatively new Perl programmer -- i normally code in either C,C++ or Java. i'm working as an intern this summmer, and working on a red-black binary tree implementation problem. i'm pretty sure it's a Perl syntax problem. Not blessed w/ vast knowledge about the language, it would be great if i could get some help! here's the situation: after i delete a node, and modify the necessary parent/child pointers, my tree becomes corrupted, and several nodes near the region where a node was deleted as a result of the delete function call lose their parent pointers. at the end of my delete function (displayed below) i return my "successor" node (the smallest node larger than the node being deleted). if the deleted node doesn't have a left or right child, this "successor" node is the node itself. in this situation, once i exit the delete function, i lose information about the parent pointers for the nodes to the left or right of the deleted node (which are moved up, and become the children of the deleted node's parent). instead, their parent pointers are set to undefined. 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. it's just that when there is no receiver (hence $curr is garbage collected) that the tree becomes corrupted. this is strange, because the new pointers set after the node is deleted don't intersect with the returned node. any hints on how to fix this? both my mentor and i are officially stumped. thanks! - frustrated_intern code shown below:
Edit g0n: closed b tag after "here's the situation"
Back to
Seekers of Perl Wisdom
|
|