From 579b3dc0dea8e8afe09b1ea8571399cf9a9abe4c Mon Sep 17 00:00:00 2001 From: lukejelse04 Date: Thu, 8 Jul 2021 13:58:54 +0100 Subject: [PATCH] Removed whitespace and altered program to allow for constant node removal for tests --- BinaryTree/BinaryTree/Program.cs | 6 ++++-- BinaryTree/BinaryTree/tree.cs | 15 +++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/BinaryTree/BinaryTree/Program.cs b/BinaryTree/BinaryTree/Program.cs index d1573e6..70c44e7 100644 --- a/BinaryTree/BinaryTree/Program.cs +++ b/BinaryTree/BinaryTree/Program.cs @@ -15,16 +15,18 @@ namespace BinaryTree tree.Add(random.Next(0, 100)); } - tree.Print(tree.Root); - while (true) { + Console.Clear(); + tree.Print(tree.Root); Console.WriteLine("-------------------------------------"); Console.WriteLine("Delete node: "); tree.Delete(Convert.ToInt32(Console.ReadLine())); tree.Print(tree.Root); + Console.ReadLine(); + } } diff --git a/BinaryTree/BinaryTree/tree.cs b/BinaryTree/BinaryTree/tree.cs index 9b4ad8c..507737e 100644 --- a/BinaryTree/BinaryTree/tree.cs +++ b/BinaryTree/BinaryTree/tree.cs @@ -100,13 +100,6 @@ namespace BinaryTree Current.Data = temp.Data; //Find if the temp node is a left or a right now before deleting. - //Adopt subtree Nodes// -- Subtrees are lost (If temp node is only 1 level down, data is lost) - // if (temp.GetLeft() != null) - // { - // temp.GetParent().SetRight(temp.GetLeft()); - // }else{ - // temp.GetParent().SetRight(null); - // } if(temp.GetParent() == Current){ @@ -121,6 +114,12 @@ namespace BinaryTree temp.GetParent().SetRight(null); } } + //*Code not currently working - Doesn't confidently replace the root or parent nodes of each item that is deleted + // temp.SetParent(Current.GetParent()); + // if (Current.GetParent() == null) + // { + // Root = Current; + // } return true; @@ -139,7 +138,7 @@ namespace BinaryTree } } - if (Current.Data < Current.GetParent().Data) + if (Current == Root || Current.Data < Current.GetParent().Data) { LeftFlag = true; }