nassss

Untitled

Mar 21st, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public int Height()
  2. {
  3. if(this.Root == null)
  4. {
  5. return -1;
  6. }
  7. return Height(this.Root);
  8. }
  9. private int Height (BinaryTreeNode node)
  10. {
  11. if (node.LeftChild == null && node.RightChild == null)
  12. {
  13. return 0;
  14. }
  15.  
  16. int leftHeight = 0;
  17. int rightHeight = 0;
  18.  
  19. if (this.Root.LeftChild != null)
  20. {
  21. leftHeight = Height(node.LeftChild);
  22. }
  23. if (this.Root.RightChild != null)
  24. {
  25. rightHeight = Height(node.RightChild);
  26. }
  27. return Math.Max(++leftHeight, ++rightHeight);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment