Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 parent;

TreeNode left;

TreeNode right;

/**

* 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 parent)

{

this.parent = parent;

}

/**

* get this node's parent node

* @return the node's parent node

*/

public TreeNode getParent()

{

return parent;

}

/**

* set this node's left child node as given node

* @param left The given node

*/

public void setLeft(TreeNode left)

{

this.left = left;

}

/**

* get this node's left child node

* @return the node's left child node

*/

public TreeNode getLeft()

{

return left;

}

/**

* set this node's right child node as given node

* @param right The given node

*/

public void setRight(TreeNode right)

{

this.right = right;

}

/**

* get this node's right child node

* @return the node's right child node

*/

public TreeNode getRight()

{

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

sharing of non-material benefits such as time and affection;

Answered: 1 week ago