Question: please help with the todo parts: package tree; import java.util.Optional; public class TreeNode { private T value; private Optional > left; private Optional > right;

please help with the todo parts:
package tree;
import java.util.Optional;
public class TreeNode {
private T value;
private Optional> left;
private Optional> right;
Optional> left(){ return Optional.empty();}// TODO
Optional> right(){return Optional.empty();}// TODO
T value(){return null;}
// Code with NULL
// private static String printInorder(TreeNode node){
// if (node == null){
// return "";
//}
// return printInorder(node.left())+ node.value()+ printInorder(node.right());
//}
// public String printInorder(){
// return printInorder(this);
public String printInorder(){
return printInorder(Optional.of(this));
// could be Optional.ofNullable(this)
}
private static String printInorderNonNull(TreeNode node){
return printInorder(node.left())+ node.value()+ printInorder(node.right());
}
static String printInorder(Optional> node){
return node.map(TreeNode::printInorderNonNull)
.orElse("");
}
public boolean lookup(T value){
// TODO
return false;
}
public String printPreorder(){
// TODO
return "";
}
public String printPostorder(){
// TODO
return "";
}
public int size(){
return size(root);
}
public int height(){
// TODO
return 0;
}
public void mirror(){
// TODO
}
public void doubleTree(){
// TODO
}
public boolean sameTree(TreeNode other){
// TODO
return false;
}
}
ppesae

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!