Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int Height()
- {
- if(this.Root == null)
- {
- return -1;
- }
- return Height(this.Root);
- }
- private int Height (BinaryTreeNode node)
- {
- if (this.Root.LeftChild == null && this.Root.RightChild == null)
- {
- return 0;
- }
- int leftHeight = 0;
- int rightHeight = 0;
- if (this.Root.LeftChild != null)
- {
- leftHeight = Height(this.Root.LeftChild);
- }
- if (this.Root.RightChild != null)
- {
- rightHeight = Height(this.Root.RightChild);
- }
- return Math.Max(++leftHeight, ++rightHeight);
- }
Advertisement
Add Comment
Please, Sign In to add comment