Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //method in class Nodo
- public Integer eachNodeHeight(){
- if(this.left == null && this.right == null){
- return 0;
- }
- if(this.left != null && this.right != null){
- if(this.left.eachNodeHeight() > this.right.eachNodeHeight()){
- this.height = this.left.eachNodeHeight() + 1;
- return this.height;
- }
- else{
- this.height = this.right.eachNodeHeight() + 1;
- return this.height;
- }
- }
- if(this.left != null && this.right == null){
- this.height = this.left.eachNodeHeight() + 1;
- return this.height;
- }
- else{
- this.height = this.right.eachNodeHeight() + 1;
- return this.height;
- }
- }
- //method in class BinaryTree
- public Integer eachNodeHeight(){
- if(this.root == null)
- return 0;
- else
- return this.root.eachNodeHeight();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement