a. Reads the integers in the given text file Input2.txt) and insert the values into a BST in the given order using the insert method and let first be the link to this tree. b. Use the given method preOrder (in the BinaryNode) class to print the contents of the tree you created in al. c. Implement andcall the method splitTree method with the value x-12, and thelinks first and second. d. Use the method printpreOrder to print the contents of the tree that has second as a link to its root node. e. Use the method printpreOrder to print the contents of the tree that has first as a link to its root node.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

only c

here is "BinaryNode.java"

// BinaryNode class; stores a node in a tree. // // CONSTRUCTION: with (a) no parameters, or (b) an Object, // or (c) an Object, left child, and right child. // // *******************PUBLIC OPERATIONS********************** // int size( ) --> Return size of subtree at node // int height( ) --> Return height of subtree at node // void printPostOrder( ) --> Print a postorder tree traversal // void printInOrder( ) --> Print an inorder tree traversal // void printPreOrder( ) --> Print a preorder tree traversal // BinaryNode duplicate( )--> Return a duplicate tree /** * Binary node class with recursive routines to * compute size and height. */ class BinaryNode { public BinaryNode( ) { this( 0, null, null ); } public BinaryNode( int theElement, BinaryNode lt, BinaryNode rt ) { element = theElement; left = lt; right = rt; } /** * Return the size of the binary tree rooted at t. */ public static int size( BinaryNode t ) { if( t == null ) return 0; else return 1 + size( t.left ) + size( t.right ); } /** * Return the height from a node to the root node of the binary tree. */ public static int height( BinaryNode root) { int lh=0; int rh=0; int dummy=0; if (root != null) { // leaf node’s height is zero if ((root.left == null) && (root.right == null)) return 0; else { lh = height(root.left); rh = height(root.right); if (lh > rh){ dummy = 1 + lh; }else{ dummy = 1 + rh; } return dummy; } } return -1; } // Print tree rooted at current node using preorder traversal. public void printPreOrder( ) { System.out.println( element ); // Node if( left != null ) left.printPreOrder( ); // Left if( right != null ) right.printPreOrder( ); // Right } // Print tree rooted at current node using postorder traversal. public void printPostOrder( ) { if( left != null ) left.printPostOrder( ); // Left if( right != null ) right.printPostOrder( ); // Right System.out.println( element ); // Node } // Print tree rooted at current node using inorder traversal. public void printInOrder( ) { if( left != null ) left.printInOrder( ); // Left System.out.println( element ); // Node if( right != null ) right.printInOrder( ); // Right } /** * Return a reference to a node that is the root of a * duplicate of the binary tree rooted at the current node. */ public BinaryNode duplicate( ) { BinaryNode root = new BinaryNode( element, null, null ); if( left != null ) // If there's a left subtree root.left = left.duplicate( ); // Duplicate; attach if( right != null ) // If there's a right subtree root.right = right.duplicate( ); // Duplicate; attach return root; // Return resulting tree } public int getElement( ) { return element; } public BinaryNode getLeft( ) { return left; } public BinaryNode getRight( ) { return right; } public void setElement( int x ) { element = x; } public void setLeft( BinaryNode t ) { left = t; } public void setRight( BinaryNode t ) { right = t; } private int element; private BinaryNode left; private BinaryNode right; }

Write a Java program that:
a. Reads the integers in the given text file Input2.txt) and insert the values into a BST in the
given order using the insert method and let first be the link to this tree.
b. Use the given method preOrder (in the BinaryNode) class to print the contents of the tree
you created in a).
c. Implement andcall the method splitTree method with the value x=12, and thelinks first and
second.
d. Use the method printpreOrder to print the contents of the tree that has second as a link to
its root node.
e. Use the method printpreOrder to print the contents of the tree that has first as a link to its
root node.
Transcribed Image Text:Write a Java program that: a. Reads the integers in the given text file Input2.txt) and insert the values into a BST in the given order using the insert method and let first be the link to this tree. b. Use the given method preOrder (in the BinaryNode) class to print the contents of the tree you created in a). c. Implement andcall the method splitTree method with the value x=12, and thelinks first and second. d. Use the method printpreOrder to print the contents of the tree that has second as a link to its root node. e. Use the method printpreOrder to print the contents of the tree that has first as a link to its root node.
input2 - Notepad
File Edit
Format View Help
10
15
25
30
12
4
5
19
22
13
Transcribed Image Text:input2 - Notepad File Edit Format View Help 10 15 25 30 12 4 5 19 22 13
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY