From 22542309582b06bb466819748fc2d5ed288580a6 Mon Sep 17 00:00:00 2001 From: lukejelse04 Date: Thu, 8 Jul 2021 17:42:43 +0100 Subject: [PATCH] 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. --- BinaryTree/BinaryTree/node.cs | 1 - BinaryTree/BinaryTree/tree.cs | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/BinaryTree/BinaryTree/node.cs b/BinaryTree/BinaryTree/node.cs index d0e2bd3..a9d082f 100644 --- a/BinaryTree/BinaryTree/node.cs +++ b/BinaryTree/BinaryTree/node.cs @@ -48,6 +48,5 @@ namespace BinaryTree Right = _Right; } - } } \ No newline at end of file diff --git a/BinaryTree/BinaryTree/tree.cs b/BinaryTree/BinaryTree/tree.cs index 652c037..ecde520 100644 --- a/BinaryTree/BinaryTree/tree.cs +++ b/BinaryTree/BinaryTree/tree.cs @@ -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) {