Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java program to implement it. Study the three Java source files. as listed BELOW Create a project in eclipse to run the code. Then,

Use Java program to implement it. 

Study the three Java source files. as listed BELOW

Create a project in eclipse to run the code.

Then, modify the code so that it creates and prints the tree in the "Binary Tree.doc" file as shown BELOW

 1. /** This program demonstrates construction and traversal of binary trees. */ public class BinaryTreeNodes { // Creates a binary tree from nodes and traverses it in // in inorder. public static void main(String[] args) { Node root = null; // Will be root of the binary tree. Node aNode = new Node(10); aNode.left = new Node(20); Node dNode = new Node(40); Node cNode = new Node(30, dNode, new Node(50)); aNode.right = cNode; root = aNode; System.out.print("Inorder traversal is: "); NodeUtilities.inorder(root); System.out.println(); } } 

2.

/** Node class. */ public class Node { int value; Node left, right; // Constructor for leaf nodes. Node(int val) { value = val; left = null; right = null; } // Constructor for non-leaf nodes. Node(int val, Node leftChild, Node rightChild) { value = val; left = leftChild; right = rightChild; } } 

3.

/** This class has various utility methods for working with nodes. */ public class NodeUtilities { /** Inorder traversal of a binary tree rooted at a node. @param btree : The root of the binary tree. */ static public void inorder(Node btree) { if (btree != null) { inorder(btree.left); System.out.print(btree.value + " "); inorder(btree.right); } } } 

"Binary Tree.doc"

image text in transcribed

..|..1..|.. 2 ..|.3 ..:.. 4 ...|..5..|..67. D Binary Treesnap 90 100

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions