Java Generics binary tree

| October 16, 2015

Introduction:

In this project you will create a generic binary tree using Java Generics.

Description:

Create a generic class called GenBinTree.  GenBinTree will use nodes
that store a value of the generic type to store its contents.
This tree will not be a search tree (no ordering of nodes by value).

It should have the following methods.  The methods should
all operate on the object making the call (none are static).

Perform checking of the parameters and throw exceptions where
appropriate.

Detailed instructions in attachment

Introduction:

In this project you will create a generic binary tree using Java Generics.

Description:

Create a generic class called GenBinTree.  GenBinTree will use nodes
that store a value of the generic type to store its contents.
This tree will not be a search tree (no ordering of nodes by value).

It should have the following methods.  The methods should
all operate on the object making the call (none are static).

Perform checking of the parameters and throw exceptions where
appropriate.

20 points
a) add
Adds a node to the tree as described in the example below.
Will only add leaf nodes.  Ignores duplicates.

The add operation will work by receiving a string, as shown in the following example:

myTree.add(“100”);
myTree.add(“L”, “50”);
myTree.add(“R”, “150”);
myTree.add(“LL”, “40”);
myTree.add(“LLR”, “45”);

The resulting tree should look like this:

100
/   \
50   150
/
40
\
45

10 points
b) find
Returns true if value passed is in the tree.

10 points
c) remove
Removes the node having the passed value.  Only leaves may be removed.

10 points
d) Swap
Swaps children of node having the passed value.

10 points
e) Mirror
Makes the tree a mirror image of the original tree.
For the tree above:

100                 100
/   \               /   \
50   150    –>     150  50
/                           \
40                           40
\                           /
45                         45

10 points
f) RotateRight
Performs a single rotation on the node having the passed value.
If a RotateRight on 100 is performed:

100                  50
/   \                /   \
50   150    –>      40   100
/                      \     \
40                      45    150
\
45

10 points
g) RotateLeft
As above but left rotation.

10 points
h) CountNodes
Recursively traverses the tree and returns the count of nodes.

10 points
i) Print
Prints node values using an inorder traversal.

Get a 5 % discount on an order above $ 150
Use the following coupon code :
2020Discount
Labor-Relationship
The Case of the Missing Boeing

Category: Completed Assignments

Our Services:
Order a customized paper today!
Open chat
Hello, we are here to help with your assignments
Powered by