Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 25, Problem 25.10PE
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.
        • Call the “preorderIterator”.
        • The “while” condition is used to iterate the element.
          • Display the result
    • Define the “BST” class.
      • Declare the required variables.
      • Create a default BST class.
      • 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 “preorderIterator” class which is derived from the “java.util.Iterator”.
        • Declare and store the element into the list.
        • Inside the constructor call the “preorder” method.
        • Define the “preorder” method.
          • If the “root” is equal to null return the value.
          • Otherwise, add the element into the list and call the “preorder” method for adding element into the left and right subtree.
        • 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 interface.
      • Declare the required methods.
      • Define the required methods.

Blurred answer
Students have asked these similar questions
(Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject and then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a colour, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the colour and filled properties using the input. The program should display the area, perimeter, colour, and true or false to indicate whether it is filled or not.
(Find the nonleaves) Java Define a new class named BSTWithNumberOfNonLeaves that extends BST with the following methods: /** Return the number of nonleaf nodes */public int getNumberofNonLeaves() // BEGIN REVEL SUBMISSION class BSTWithNumberOfNonLeaves<E> extends BST<E> { /** Create a default BST with a natural order comparator */ public BSTWithNumberOfNonLeaves() { super(); } /** Create a BST with a specified comparator */ public BSTWithNumberOfNonLeaves(java.util.Comparator<E> c) { super(c); } /** Create a binary tree from an array of objects */ public BSTWithNumberOfNonLeaves(E[] objects) { super(objects); } public int getNumberOfNonLeaves() { return getNumberOfNonLeaves(root); } /** Returns the number of non-leaf nodes */ private int getNumberOfNonLeaves(TreeNode<E> root) { // WRITE YOUR CODE HERE } } // END REVEL SUBMISSION
// The language is java Part I: Use of recursive method (4 points for students who need recursion/extracredit) Description: Code a class called RecursiveMultiply in which it will accept two integer arguments entered from user; pass these integers to a recursive method that returns the multiplication result of these two integers. The multiplication can be performed as repeated addition, for example, if two integers are 7 and 4: 8 * 4 = 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 You will write the application with GUI and recursion to display the result in a noneditable text field, based on the user’s entry from two text fields, while an OK button is pressed. You will utilize the exception handling code as you did in your Lab 4 and Lab 5 to verify if data entered in the text fields are valid (numerical and positive data only). You will make your own decision if there is any explanation that is not described in this specification. Finally, code a driver program that will test your class…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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