private int Height(BinaryTreeEx node) { if (node == null) { return(0); } return(1 + Math.Max(Height(node.leftNode), Height(node.rightNode))); }
public void PrintDFS(BinaryTreeEx node, string space) { Console.WriteLine(space + node.Value); if (node.leftNode != null) { PrintDFS(node.leftNode, space + " "); } if (node.rightNode != null) { PrintDFS(node.rightNode, space + " "); } }
// part 6: tells that binary tree is prefectly balanced: copied from Greekforgreek public bool IsBalanced(BinaryTreeEx node) { if (node == null) { return(true); } LeftSubtreeHeight = Height(node.leftNode); rightSubtreeHeight = Height(node.rightNode); if (Math.Abs(LeftSubtreeHeight - rightSubtreeHeight) <= 1) { return(true); } return(false); }
public BinaryTreeEx(int value, BinaryTreeEx LN, BinaryTreeEx RN) { this.Value = value; this.leftNode = LN; this.rightNode = RN; }