Subject: Remove code
From: Kevin Chan (firstname.lastname@example.org)
Date: Fri May 03 2002 - 00:12:57 PDT
Alright, I wasn't expecting everyone to literally use my code from the
last e-mail message, but because everyone is and are claiming that there
are bugs. (Yes there was bug, the only bug was the fact that I did not set
any of the pointers on the current node to NULL. So you get the runaway
The following is the answer to the remove assignment. You may use it if
you feel you want to use the code in the AVL assignment.
DISCLAIMER: This code worked and still works under the remove assignment.
It is not guaranteed to work in the AVL assignment. The biggest thing I
can see is the fact that this remove function uses the successor but you
are expected to use the predecessor.
TreeNode* replacement = NULL;
if (RChild() && LChild())
replacement = this->Succ();
else if (RChild() && !LChild())
replacement = RChild();
else if (!RChild() && LChild())
replacement = LChild();
assert(RChild() == NULL && LChild() == NULL);
if (Parent()->LChild() == this)
assert (Parent()->RChild() == this);
This archive was generated by hypermail 2b25 : Fri May 03 2002 - 00:13:10 PDT