Problem 3 Linkbased Binary Tree Download this java file Com

Problem #3 \" Link-based Binary Tree Download this java file. Complete the height) and When you think you are done, submit your solution in Web-CAT subtreesizet) methods so that they compute the height of the node and the number of nodes in the sode\'s subtree, respectively How To Submit Submit cach of your solutions to Web-CAT. They should be submitted as Weck09Problemo1, Week09Problem02, and Week09Problem03, respectively

Solution

public class BTNode { protected E element; protected BTNode left; protected BTNode right; protected BTNode parent; public BTNode(E element, BTNode parent) { this.element = element; this.parent = parent; } public int height(){ int lh = left == null ? -1 : left.height(); int rh = right == null ? -1 : right.height(); return lh > rh ? lh + 1 : rh + 1; } public int subtreeSize(){ int total = 0; if(left != null){ total += 1 + left.subtreeSize(); } if(right != null){ total += 1 + right.subtreeSize(); } return total; } }
 Problem #3 \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site