Question
Create a ClosedLab12 project folder. FOR ALL EXERCISES: Make sure you place a comment block at the top of the code with your name and
Create a ClosedLab12 project folder.FOR ALL EXERCISES:Make sure you place a comment block at the top of the code with your name and your partner's name.
Before starting the lab, download the following archive file.We will be using it for this lab.
- cse2123libs.jar
To use this archive file with your project, save it to your eclipse workspace folder.Then right-click your ClosedLab12 folder and go to Properties.Select "Java Build Path", then select "Libraries" and click the "Add External JARs" button.Browse to where you saved the above jar file and select it and click the Open button.Then click OK.
The JAR file contains an implementation of a binary tree node named TreeNode
In your ClosedLab12 project folder, import the following files:
- ClosedLab12.java
- ClosedLab12Main.java
Examine ClosedLab12.java first.There is no actual code in this file - only a set of stubs.For Exercise 1 you should just look at the insert method.You will be implementing the binary tree insert algorithm for this step.This algorithm is a simple recursive algorithm:
- If the element to be inserted is less than the element at the current node:
- If the current node has no left child, create a new node using the new element and make it the left child of the current node
- Otherwise, insert the element into the tree that has the left child node as its root (i.e. make a recursive call to insert)
- If the element to be inserted is greater than or equal to the element at the current node:
- If the current node has no right child, create a new node using the new element and make it the right child of the current node
- Otherwise, insert the element into the tree that has the right child node as its root
You can see your code in operation by using the main method in ClosedLab12Main.java.If you have implemented the insert properly, the list should be displayed in sorted order.(The toString() method of the TreeNode
Now create a JUnit class to test your code with.Right click on ClosedLab12.java and select "JUnit Test Case".When you create this class, go ahead and include all of the methods in the ClosedLab12 class.You do not necessarily need to use the TDD model discussed in class to develop this code, but come up with a number of test cases to convince yourself that your code is working and implement them following the model of setting up a tree given in ClosedLab12Main.java.You can use the fact that TreeNode
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