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:
lukejelse04 2021-07-08 17:42:43 +01:00
parent c9f16de23b
commit 2254230958
2 changed files with 5 additions and 3 deletions

View File

@ -48,6 +48,5 @@ namespace BinaryTree
Right = _Right; Right = _Right;
} }
} }
} }

View File

@ -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)
{ {