Question
Please help me make sure existing code is correct and then figure out the rest of the code that I bolded in treenode.java. Thank you!
Please help me make sure existing code is correct and then figure out the rest of the code that I bolded in treenode.java. Thank you!
public class TreeNode
{
E data;
TreeNode
TreeNode
TreeNode
/**
* constructor construct a tree node with every field as null
*/
public TreeNode()
{
}
/**
* constructor construct a tree node with all node referece null to hold given data
* @param data The given data of type E
*/
public TreeNode(E data)
{
this.data = data;
this.left = null;
this.right = null;
this.parent = null;
}
/**
* set this node's data as given data
* @param data The given data of type E
*/
public void setData(E data)
{
this.data = data;
}
/**
* get this node's data
* @return the node's data of type E
*/
public E getData()
{
return data;
}
/**
* set this node's parent node as given node
* @param parent The given node
*/
public void setParent(TreeNode
{
this.parent = parent;
}
/**
* get this node's parent node
* @return the node's parent node
*/
public TreeNode
{
return parent;
}
/**
* set this node's left child node as given node
* @param left The given node
*/
public void setLeft(TreeNode
{
this.left = left;
}
/**
* get this node's left child node
* @return the node's left child node
*/
public TreeNode
{
return left;
}
/**
* set this node's right child node as given node
* @param right The given node
*/
public void setRight(TreeNode
{
this.right = right;
}
/**
* get this node's right child node
* @return the node's right child node
*/
public TreeNode
{
return right;
}
/**
* check if this node is the left child of its parent
* @return true if this node is the left child of its parent; false otherwise.
* If this node is root, i.e. it has no parent, it also return false
*/
public boolean isLeftChild(){
}
/**
* check if this node is the right child of its parent
* @return true if this node is the right child of its parent; false otherwise.
* If this node is root, i.e. it has no parent, it also return false
*/
public boolean isRightChild(){
}
/**
* check if this node is a leaf
* @return true if this node is a leaf; false otherwise.
*/
public boolean isLeaf(){
return left == null && right == null; //Is this correct?
}
/**
* check if this node is a root
* @return true if this node is a root; false otherwise.
*/
public boolean isRoot(){
return parent == null;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started