Question
Book Icon
Chapter 25, Problem 25.9PE
Program Plan Intro

Program Plan:

  • Include the required import statement.
  • Define the main class.
    • Define the main method using public static main.
      • Allocate memory to the class “Test”.
      • Define the “Test” class.
        • Declare the object for the BST.
        • Insert the values into the tree.
        • Call the “postorder” method.
        • The try-catch block is used to get the input from the user and do the postorder traversal.
          • Display the output.
    • Define the “BST” class.
      • Declare the required variables.
      • Create a default BST class.
      • Define the “clone” method.
        • Create an object for the “BST” class.
        • Call the “copy” method with the argument.
        • Return the tree.
      • Define the “copy” method.
        • If the “s” is not null, insert the element into the tree.
          • Copy the “t” value into left and right subtrees.
      • Define the “equals” method.
        • Create the object for the array list.
        • Call the “toArray” method.
        • Return the two array.
      • Define the ArrayList of “getElementInorder” method
        • Create the object for the array list.
        • Call the “getElementInorder” method.
        • Return the list.
      • Define the “getElementInorder” method.
        • If the “root” is equal to null, return the value.
        • Call the “getElementInorder” method.
        • Add the element into the list.
        • Call the “getElementInorder” method.
      • Create a binary tree from an array of objects.
      • Define the “search” method.
        • Start the traverse from the root of the tree.
        • If the search element is in the left subtree set that value in “current” variable otherwise set the “current” variable as right subtree value.
      • Define the “insert” method.
        • If the root is null create the tree otherwise insert the value into left or right subtree.
      • Define the “createNewNode”
        • Return the result of new node creations.
      • Define the “inorder”
        • Inorder traverse from the root.
      • Define the protected “inorder” method
        • Traverse the tree according to the inorder traversal concept.
      • Define the “postorder”
        • Postorder traverse from the root.
      • Define the protected “postorder” method
        • Traverse the tree according to the postorder traversal concept.
      • Define the “preorder”
        • Preorder traverse from the root.
      • Define the protected “preorder” method
        • Traverse the tree according to the preorder traversal concept.
      • Define the “TreeNode” class
        • Declare the required variables.
        • Define the constructor.
      • Define the “getSize” method.
        • Return the size.
      • Define the “getRoot” method
        • Return the root.
      • Define the “java.util.ArrayList” method.
        • Create an object for the array list.
        • If the “current” is not equal to null, add the value to the list.
        • If the “current” is less than 0, set the “current” as left subtree element otherwise set the “current” as right subtree element.
        • Return the list.
      • Define the “delete” method.
        • If the “current” is not equal to null, add the value to the list.
        • If the “current” is less than 0, delete the “current” as left subtree element otherwise delete the “current” as right subtree element.
        • Return the list.
      • Define the “iterator” method.
        • Call the “inorderIterator” and return the value.
      • Define the “inorderIterator”
        • Create an object for that method and return the value
      • Define the “inorderIterator” class.
        • Declare the variables.
        • Define the constructor.
          • Call the “inorder” method.
        • Define the “inorder” method.
          • Call the inner “inorder” method with the argument.
        • Define the TreeNode “inorder” method.
          • If the root value is null return the value, otherwise add the value into the list.
        • Define the “hasNext” method
          • If the “current” value is less than size of the list return true otherwise return false.
        • Define the “next” method
          • Return the list.
        • Define the “remove” method.
          • Call the delete method.
          • Clear the list then call the “inorder” method.
      • Define the “clear” method
        • Set the values to the variables
    • Define the interface.
      • Declare the required methods.
      • Define the required methods.

Blurred answer
Students have asked these similar questions
(Test perfect binary tree) JAVA A perfect binary tree is a complete binary tree with all levels fully filled. Define a new class named BSTWithTestPerfect that extends BST with the following methods: (Hint: The number of nodes in a perfect binary tree is 2^(height+1) - 1.) /** Returns true if the tree is a perfect binary tree */public boolean isPerfectBST() Use https://liveexample.pearsoncmg.com/test/Exercise25_03.txt to test your code. Class Name: Exercise25_03
(Test perfect binary tree) A perfect binary tree is a complete binary tree with all levels fully filled. Define a new class named BSTWithTestPerfect that extends BST with the following methods: (Hint: The number of nodes in a perfect binary tree is 2^(height+1) - 1.) /** Returns true if the tree is a perfect binary tree */ public boolean isPerfectBST() Use https://liveexample.pearsoncmg.com/test/Exercise25_03.txt to test your code. Class Name: Exercise25 03
(Java) How can I implement a binary search tree in a program to store data, and use the delete method to trim the tree? The program should have a 'populate' button that obtains a string from the user, creates a sorted binary search tree of characters, and prints the tree using the DisplayTree class. It should also print the characters on one line in sorted order by traversing the tree in inorder fashion. The program should also have a 'Trim Tree' button that obtains a second line of input to delete characters from the tree, trimming the tree accordingly. It should ignore characters that are not in the tree, and only delete one character for each occurrence in the second line of input. When all characters from the second line have been deleted from the tree, the program should print the remaining characters in the tree using the DisplayTree class. The output should be labeled appropriately, and no spaces or commas should be used between tree elements in the inorder traversal.Here is the…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education