nassss

Untitled

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