Question: complete this: Please keep all the existing codes and imeplement the functions that are not completed. import java.util.LinkedList; import java.util.Queue; import java.util.function.Consumer; docs.oracle.com / javase
complete this:
Please keep all the existing codes and imeplement the functions that are not completed.
import java.util.LinkedList;
import java.util.Queue;
import java.util.function.Consumer; docs.oracle.comjavasedocsapijavautilfunctionConsumerhtml
public class BinaryTree
protected class Node
T data;
Node leftChild;
Node rightChild;
Node parent;
Node
leftChild null;
rightChild null;
parent null;
NodeNode theParent
leftChild null;
rightChild null;
parent theParent;
protected Node root;
protected Boolean verbose;
BinaryTree
root null;
verbose false;
public void setVerbose
verbose true;
public void unsetVerbose
verbose false;
public int numberOfNodes
note that root.left and root.right
return numberOfNodesroot;
int numberOfNodesNode t
if null t
return ;
return numberOfNodestleftChild numberOfNodestrightChild;
public int height
return heightroot;
int heightNode t
if null t
return ;
return Math.maxheighttleftChild heighttrightChild;
public boolean isEmpty
return null root;
public void clear
yay for garbage collection
root null;
enum DfsType
PREFIX,
INFIX,
POSTFIX
void recursiveDfsDfsType dfs Node t Consumer actionClass
if null t
return;
if dfsequalsDfsTypePREFIX
actionClass.accepttdata;
recursiveDfsdfs tleftChild, actionClass;
if dfsequalsDfsTypeINFIX
actionClass.accepttdata;
recursiveDfsdfs trightChild, actionClass;
if dfsequalsDfsTypePOSTFIX
actionClass.accepttdata;
public void dfsPrefixConsumer actionObject
recursiveDfsDfsTypePREFIX, root, actionObject;
public void dfsInfixConsumer actionObject
recursiveDfsDfsTypeINFIX, root, actionObject;
public void dfsPostfixConsumer actionObject
recursiveDfsDfsTypePOSTFIX, root, actionObject;
public void bfsConsumer actionObject
if root null
return;
Queue queue new LinkedList;
queue.addroot;
while queue.isEmpty
Node current queue.poll;
actionObject.acceptcurrentdata;
if currentleftChild null
queue.addcurrentleftChild;
if currentrightChild null
queue.addcurrentrightChild;
StringBuilder reversedInorderNode nd int indent
var rv new StringBuilder;
if null nd
if null ndrightChild
rvappendreversedInorderndrightChild, indent ;
for int i ; i indent ; i
rvappend;
rvappendindent ;
rvappendnddata;
rvappend
;
if null ndleftChild
rvappendreversedInorderndleftChild, indent ;
return rv;
@Override
public String toString
return reversedInorderroottoString;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
