You are to design a Java program to perform the following tasks:
read a sequence of integers, 60, 20, 100, 35, 15, 200, 75, 150, 6, 17, and 40, and construct a binary search tree, called T1.
use the inorder procedure to print the nodes
count the number of leaf nodes of T1.
swap the nodes of T1 to construct a new tree, called T2.
use the postorder function to print the nodes of T2.
use the function compare to see if T1 is identical to T2.
read another sequence of integers, 60, 100, 20, 15, 35, 75, 200, 6, 17, 40, 150, and construct another tree, called T3.
use the function Compare to see if T1 is identical to T3.
Delete the node containing 15 from the tree T3
Use the inorder to display the nodes after deletion
Display the 5th node of the tree T3 using INORDER
You may need to design the following functions:
Function Build: read a sequence of integers and construct a binary search tree.
Function Inorder: based on the BST tree built, conduct the "INORDER" traversal and print the value of each node when visited.
Function Postorder: based on the BST tree built, conduct the "POSTORDER" traversal and print the value of each node when visited.
Function Count: write a function that counts the number of leaf nodes in the tree and return the count. Do not use unnecessary local variables and parameters.
Function Swap: swap the left and right children(subtree) recursively of every node of the given tree.
Function Compare: return TRUE if the two given trees are identical.
Using appropriate messages to explain each output described above.
Comments: You are not allowed to use the built_in tree class available in Java.
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.