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;
|
Right = _Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -98,19 +98,22 @@ namespace BinaryTree
|
|||||||
if(temp.GetParent() == Current){
|
if(temp.GetParent() == Current){
|
||||||
//If the current node is parent to our replacing node. (Only 1 level down)
|
//If the current node is parent to our replacing node. (Only 1 level down)
|
||||||
Current.SetLeft(temp.GetLeft());
|
Current.SetLeft(temp.GetLeft());
|
||||||
|
if (temp.GetLeft() != null)
|
||||||
|
{
|
||||||
|
temp.GetLeft().SetParent(temp.GetParent());
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
//If we could traverse down the left hand side
|
//If we could traverse down the left hand side
|
||||||
if (temp.GetLeft() != null)
|
if (temp.GetLeft() != null)
|
||||||
{
|
{
|
||||||
temp.GetParent().SetRight(temp.GetLeft());
|
temp.GetParent().SetRight(temp.GetLeft());
|
||||||
temp.GetLeft().SetParent(temp.GetParent());//---
|
temp.GetLeft().SetParent(temp.GetParent());
|
||||||
}else{
|
}else{
|
||||||
temp.GetParent().SetRight(null);
|
temp.GetParent().SetRight(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
}else if(Current.GetLeft() != null || Current.GetRight() != null)
|
}else if(Current.GetLeft() != null || Current.GetRight() != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user