diff --git a/BinaryTree/Program.cs b/BinaryTree/Program.cs index 3d48f5f..1bc95a1 100644 --- a/BinaryTree/Program.cs +++ b/BinaryTree/Program.cs @@ -20,8 +20,9 @@ namespace BinaryTree Console.Clear(); tree.Print(tree.Root); Console.WriteLine("-------------------------------------"); + tree.InOrderTraversal(tree.Root); Console.WriteLine("Delete node: "); - + tree.Delete(Convert.ToInt32(Console.ReadLine())); } diff --git a/BinaryTree/node.cs b/BinaryTree/node.cs index 0c82bc6..4a19bbe 100644 --- a/BinaryTree/node.cs +++ b/BinaryTree/node.cs @@ -14,38 +14,38 @@ namespace BinaryTree public int EndPos { get { return StartPos + Size; } set { StartPos = value - Size; } } - public node(dynamic _Data = null, - node _Parent = null, - node _Left = null, - node _Right = null){ + public node(dynamic data = null, + node parent = null, + node left = null, + node right = null){ //New node for a Binary Tree. Values can be set to null if they are not present - Data = _Data; - Parent = _Parent; - Left = _Left; - Right = _Right; + Data = data; + Parent = parent; + Left = left; + Right = right; } public node GetParent(){ return Parent; } - public void SetParent(node _Parent){ - Parent = _Parent; + public void SetParent(node parent){ + Parent = parent; } public node GetLeft(){ return Left; } - public void SetLeft(node _Left){ - Left = _Left; + public void SetLeft(node left){ + Left = left; } public node GetRight(){ return Right; } - public void SetRight(node _Right){ - Right = _Right; + public void SetRight(node right){ + Right = right; } } diff --git a/BinaryTree/tree.cs b/BinaryTree/tree.cs index 69d69ff..9455b34 100644 --- a/BinaryTree/tree.cs +++ b/BinaryTree/tree.cs @@ -183,7 +183,17 @@ namespace BinaryTree } + public void InOrderTraversal(node current){ + if (current.GetLeft() != null) + InOrderTraversal(current.GetLeft()); + + Console.Write($"{current.Data} -> "); + + if (current.GetRight() != null) + InOrderTraversal(current.GetRight()); + + } //print Method functions @@ -264,6 +274,7 @@ namespace BinaryTree private void Print(string s, int top, int left, int right = -1) { + Console.SetCursorPosition(left, top); if (right < 0) right = left + s.Length; while (Console.CursorLeft < right) Console.Write(s);