Finally finished the delete method, it was still missing a line that should've assigned parents for a left subtree... but it didn't - Many hours of hair pulling later and its finally finished.
This commit is contained in:
parent
c9f16de23b
commit
2254230958
@ -48,6 +48,5 @@ namespace BinaryTree
|
||||
Right = _Right;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -98,19 +98,22 @@ namespace BinaryTree
|
||||
if(temp.GetParent() == Current){
|
||||
//If the current node is parent to our replacing node. (Only 1 level down)
|
||||
Current.SetLeft(temp.GetLeft());
|
||||
if (temp.GetLeft() != null)
|
||||
{
|
||||
temp.GetLeft().SetParent(temp.GetParent());
|
||||
}
|
||||
}else{
|
||||
//If we could traverse down the left hand side
|
||||
if (temp.GetLeft() != null)
|
||||
{
|
||||
temp.GetParent().SetRight(temp.GetLeft());
|
||||
temp.GetLeft().SetParent(temp.GetParent());//---
|
||||
temp.GetLeft().SetParent(temp.GetParent());
|
||||
}else{
|
||||
temp.GetParent().SetRight(null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
}else if(Current.GetLeft() != null || Current.GetRight() != null)
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user