Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 21, Problem 6PC
Program Plan Intro

Binary Tree Input and Display

Program plan:

  • Import required packages.
  • Define the class named “JTreeDemo”.
    • Declare required private variables.
    • Define the constructor.
      • Initialize the values.
      • Load the “JTree”.
    • Give function definition “readData ()” to read data from the file.
      • Create the objects for “FileInputStream”, “InputStreamReader”, and “BufferedReader” in order to read the file
      • Declare variables “line”, and “countNode”.
      • Inside the “try” block,
        • Do until the file becomes empty using “while” condition.
          • Check if the line contains the given matches,
            • Assign the values to “numNodes”.
          • Else,
            • Assign line to “data[countNode]”.
            • Increment the value of “countNode”.
        • Close the file.
              • Catch the exception using “catch” block and print the exception.
    • Give function definition to populate the tree.
      • Create an object for “DefaultMutableTreeNode”.
      • Loop through the number of nodes.
        • Split the string.
        • Check if the length is greater than 1.
          • Add the node to the tree.
          • Loop through the length of node.
            • Add the node to the tree.
        • Check if the length is equal to 1.
          • Add the node to the tree.
              • Load the nodes to the tree.
    • Give function definition to create GUI.
      • Create a frame and add the tree to the frame.
      • Set the close operation and call the function “pack ()”.
      • Make the frame visible.
    • Give “main ()” function.
      • Assign a filename to the variable.
      • Create an object for the class.
      • Call the function “readData ()”.
      • Call the function “populateTree ()”.
      • Call the function “createAndShowGUI()”.

Blurred answer
Students have asked these similar questions
Program 3: Binary Search Tree Program Objective The primary objective of this program is to learn to implement binary search trees and to combine their functionalities with linked lists. Program Description In a multiplayer game, players' avatars are placed in a large game scene, and each avatar has its information in the game. Write a program to manage players' information in a multiplayer game using a Binary Search (BS) tree for a multiplayer game. A node in the BS tree represents each player. Each player should have an ID number, avatar name, and stamina level. The players will be arranged in the BS tree based on their ID numbers. If there is only one player in the game scene, it is represented by one node (root) in the tree. Once another player enters the game scene, a new node will be created and inserted in the BS tree based on the player ID number. Players during the gameplay will receive hits that reduce their stamina. If the players lose all their stamina, they vanish from the…
C Programming language Part 1: You need to define a data structure for a doubly linked list and a binary search tree. Also, you need to implement the following functions: Insert Sorted LINKEDLIST insertSorted(LINKEDLIST head, int num): head points to the first node in the sorted linked list; num is a number to be inserted in in correct place in the linked list pointed at “head”. The linked list should be sorted after inserting “num”. This function returns the head of the modified head. BSTREE insert(BSTREE root, int num): root points to a node in a binary search tree; num is a number to be inserted in the tree rooted at “root”. This function returns the root of the modified tree. Find an element LINKEDLIST find(LINKEDLIST head,int num): head points to the first node of a linked list; num is a number to be searched for in the linked list started at “head”. This function returns a pointer to the node containing “num” or NULL if num is not found BSTREE find(BSTREE root,int…
Please answer in c++ Please implement BST sort and test it for correctness. The program will prompt for the name of an input file and the read and process the data contained in this file. The file contains a sequence of integer values. Read them and construct a binary search tree from the values in the order they are read. Thus; the first number read will be the root of the tree. For this exercise, you may use dynamic data, but it is better to store the numbers sequentially in an array. You do not need to balance the tree as you construct it. When you have read the last value into the BST, conduct an in‐order traversal to output the values in ascending order. Print them 10 to a line in a 5‐character wide field.   Note: there may be duplicated value in the input file – in this case each copy of the number should be kept in the tree and output. E.g. if the input was 3 5 3, the output would be 3 3 5. As usual, do not use classes or STL. text file:…
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