Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.The API documentation for TreeNode is here.You will need to use this data type to implement some of the binary tree algorithms given below.Quickly review the API documentation for TreeNode - you can see that it allows you all of the functionality you need to create a binary tree, including storing data in the node, setting a left and a right child, and getting the left or right child node.

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 class has been overridden so that it provides the output of the tree as aninordertraversal of the tree - for a binary search tree this means that you will see the list in sorted order if you have coded your insert correctly).

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 implements toString() to provide a list in sorted order to test your code.Come up with a number of test cases - what kind of test cases do you need to test?Make sure you have written test cases to thoroughly test trees that have up to 5 nodes in them.(Note that you will need to add an import statement to the top of your JUnit code to be able to use the TreeNode class - see the top of ClosedLab12.java for this import statement).

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

Step: 3

blur-text-image

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

1. Which is the most abundant gas presented in the atmosphere?

Answered: 1 week ago