Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code in JAVA Write a java GTREE class to implement a generic tree, with an appropriate constructor and methods for the following Methods to find
Code in JAVA
Write a java GTREE class to implement a generic tree, with an appropriate constructor and methods for the following Methods to find and insert on the tree Method to return the height of the tree Methods to output the values from this tree in any one of the following ways Pre-order: Post-order: Level order: Left to right order of siblings Right to left order of siblings Left to right order of siblings Method to store the tree to a file per the format used for reading the file Write a Java application that reads an input file (tree.dat) that describes a flattened tree and constructs the corresponding tree. The format of the tree.dat is as follows: The first line has an integer value, m, for an m-way tree described in the file The second line indicates the value at the root. Each subsequent line will describe a node in the tree. There will be up to m+1 integer values separated by a space. The first is the value at the node, and the subsequent values indicate the values in its children nodes Example: The file describes a 3-way tree The root has value 1 Node with value 1 has children with values 8, 22, and 29 1 8 22 29 83517 3 16 19 32 22 42 191015 42 13 18 49 55 29 49 Node with value 22 has a child with value 42 There will be any number of input lines. A value will be described as a child before it is described with children i.e. parent node will be described before its children. Note that the tree is not a search-tree. You need to create a good data file and test with a test application. Write a java GTREE class to implement a generic tree, with an appropriate constructor and methods for the following Methods to find and insert on the tree Method to return the height of the tree Methods to output the values from this tree in any one of the following ways Pre-order: Post-order: Level order: Left to right order of siblings Right to left order of siblings Left to right order of siblings Method to store the tree to a file per the format used for reading the file Write a Java application that reads an input file (tree.dat) that describes a flattened tree and constructs the corresponding tree. The format of the tree.dat is as follows: The first line has an integer value, m, for an m-way tree described in the file The second line indicates the value at the root. Each subsequent line will describe a node in the tree. There will be up to m+1 integer values separated by a space. The first is the value at the node, and the subsequent values indicate the values in its children nodes Example: The file describes a 3-way tree The root has value 1 Node with value 1 has children with values 8, 22, and 29 1 8 22 29 83517 3 16 19 32 22 42 191015 42 13 18 49 55 29 49 Node with value 22 has a child with value 42 There will be any number of input lines. A value will be described as a child before it is described with children i.e. parent node will be described before its children. Note that the tree is not a search-tree. You need to create a good data file and test with a test applicationStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started