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
Question
Book Icon
Chapter 25, Problem 25.6PE
Program Plan Intro

Program Plan:

  • Include the required import statement.
  • Define the main class.
    • Define the main method using public static main.
      • Declare the object for the BST.
      • Set the BST tree with the string values.
      • Call the “getNumberOfLeaves” method and display the result.
    • Define the “BST” class.
      • Define the “getNumberOfLeaves” method.
        • Return the left node.
      • Define the override “getNumberOfLeaves” method.
        • If the “root” is null, return 0.
        • Otherwise left and right subtree values are equal to null, return 1 or return the addition of left and right leaf node.
      • 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 interface.
      • Declare the required methods.
      • Define the required methods.

Blurred answer
Students have asked these similar questions
Write the following method
- Use java RECURSION to print out this shape. - You need to call the method 2 times - use 2 or 3 for loops hints: - for (int i = 0; i < ?????; i++) sout(" ") - for (int i = 0; i < ?????; i++) sout(symbol) - put different if statements when you call yourself, one gets activated when you go up, one gets activated when you go down. - This method should be used; public static void printShape4(int row, char symbol, int currentRow) { } !!! do not use other methods, everything should be inside this method
Complete the method int getMaxRow
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning