Question
Exercise 1 Implementation of a Simple BinaryTreeNode ADT Goal: to implement a BinaryTreeNode ADT and test the operations of the ADT. A backbone of the
Exercise 1 Implementation of a Simple BinaryTreeNode ADT
Goal: to implement a BinaryTreeNode ADT and test the operations of the ADT. A backbone of the BinaryTreeNode.java is provided on moodle under Lab 5. Your first task is to fill in the methods in the class. Remember to test each of the operations in a test application. Note that we dont make an interface for this BinaryTreeNode ADT in this lab, because next week we will create a Tree ADT which uses this BinaryTreeNode internally, by then we will create an interface for a Tree. After your BinaryTreeNode ADT works correctly, created a binary tree as shown in the figure
BinaryTreeNode.java ( please edit this code to let it work) /** * BinaryTreeNode represents a node in a binary tree with a left and * right child. * * @author Java Foundations * @version 4.0 */ public class BinaryTreeNode4 10{ protected T element; protected BinaryTreeNode left, right; /** * Creates a new tree node with the specified data. */ public BinaryTreeNode(T obj) { // students complete this method } /** * Returns the number of non-null children of this node. */ public int numChildren() { // students complete this method return -1; } /** * Return the element at this node. */ public T getElement() { // students complete this method T temp = null; return temp; } /** * Return the right child of this node. */ public BinaryTreeNode getRight() { // students complete this method BinaryTreeNode temp = null; return temp; } /** * Sets the right child of this node. */ public void setRight(BinaryTreeNode node) { // students complete this method } /** * Return the left child of this node. */ public BinaryTreeNode getLeft() { // students complete this method BinaryTreeNode temp = null; return temp; } /** * Sets the left child of this node. */ public void setLeft(BinaryTreeNode node) { // students complete this method } }
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