Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. //method in class Nodo
  2. public Integer eachNodeHeight(){
  3.  
  4. if(this.left == null && this.right == null){
  5.  
  6. return 0;
  7. }
  8. if(this.left != null && this.right != null){
  9. if(this.left.eachNodeHeight() > this.right.eachNodeHeight()){
  10. this.height = this.left.eachNodeHeight() + 1;
  11. return this.height;
  12. }
  13. else{
  14. this.height = this.right.eachNodeHeight() + 1;
  15. return this.height;
  16. }
  17. }
  18.  
  19. if(this.left != null && this.right == null){
  20. this.height = this.left.eachNodeHeight() + 1;
  21. return this.height;
  22. }
  23. else{
  24. this.height = this.right.eachNodeHeight() + 1;
  25. return this.height;
  26.  
  27. }
  28.  
  29. }
  30.  
  31. //method in class BinaryTree
  32. public Integer eachNodeHeight(){
  33. if(this.root == null)
  34. return 0;
  35. else
  36. return this.root.eachNodeHeight();
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement