nbEadk traverse traverse 3 min max show #00 postorder traverse find the minimum
ID: 3739839 • Letter: N
Question
nbEadk traverse traverse 3 min max show #00 postorder traverse find the minimum node in the tree #find the maximum node in the treo display the tree Note that since the method insert takes both an int and a double as arguments: public void insert (int id, double dd) , Just make the double equai to the int value +0.9 for insert operations Add the following method to the Tree class and implement code that returns the Node with the 2. minimum value in the tree. public Node findMin() Add the following method to the Tree class and implement code that returns the Node with the maximum value in the tree B. public Node findMax() MacBook ProExplanation / Answer
**NOTE: Assuming this class declaration has a variable similar to "Node root;" which will represent root of the Tree object calling this method.
public Node findMin() {
if(root == null)
return null;
Node n,nleft,nright;
n = root;
nleft = root.left.findMin();
nright = root.right.findMin();
if(nleft.data < n.data)
n = nleft;
if(nright.data < n.data)
n = nright;
return n;
}
public Node findMax() {
if(this.root == null)
return null;
Node n,nleft,nright;
n = this.root;
nleft = this.root.left.findMax();
nright = this.root.right.findMax();
if(nleft.data > n.data)
n = nleft;
if(nright.data > n.data)
n = nright;
return n;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.