QuestionQuestion

Transcribed TextTranscribed Text

Overview Sorry for getting this youlate. As result, made the assignment far simpler thanl originally planned. Anyway. for this assignment you are going toa very basic tree with a minimal interface You don't have balance Not vet at least We'll cover thatpretty soon. Part Node Class Overview In recursively defined structures like trees all the coding (and complexity)is found in recursive structure itself Inthe case of trees the node will contain the vast amount of the logic and behavior. You aregoing create very very basic node class Mak sure come up with nice. well documer ited. and well-w itter solution. Wewill build upor it, later. create more advanced tree structures Interface Create very basic node class Allthis requiresis a left and right link (to another node) and generic data field. Itshould also have few constructors Inparticular you need one that wil create node with links t two other nodes public class Node Node() Constructor Node(String, Node, Node) Constructor thatassigns the value left and right nodes Node left Node right String value The value that the ode contains Donot declare it of type "object" void print (int indent) Unlike the other print method this one will print the structure of the tree One node will printed perline You should use prefix tree traversal Feel free to redirect the streami you like. 2 Printing the Tree To print tree. you will use the same recursion logic as printing the values. However rather than an infix traversal. this will use prefix Don't worry, you wrote the other print method already, this will be easy. Method print (int indent Print spaces for indent Print Node value and newline left print (indent 1) right print (indent 1) End Method The binary tree. the lecture nodes wou ulo create the following output 1am using spaces followed by s tring of --+'for readability You canuse spaces, dashes etc. You can use any factor you ike (2,3,etc...). +-- 42 26 7 12 Pretty cool. huh? You car see the tree. Here's asecond example with strings rather than numbers +-- Gold Rush Supplies +-- Mining Gold Pan +-- Shovel +-- Lifestyle Entertainment +-- Box for Miner' Cat +-- Concertina Food +-- Drinks Liquor Part 2: BinaryTree Class Overview While themaion logic will be found in the nodes we need to have single central zed class The purpose of the BinaryTree class isto start recursion, store some global attributes (for future versions). and much more Interface The tree class needs to store the root node. public class BinaryTree BinaryTree () Constructor BinaryTree (Node root) Constructor Node root String about () Returns text about you author of this class void print Starts recursion from the root node with indent 0. Part Testing Creating Test Tree Once you have finished your code, you need to testi using some good test data. This isn't BST so we can' just add nodes and they wil be inserted in the correct location This tree the most basic form which means that creating a test tree will require somelong declarations For example the following s 8 Java-like language that creates basic tree using the Node' constructor BinaryTree tree new BinaryTree(); tree root new Node("A", new Node ("B"), new Node ("C", new Node(*D"), new Node("E")); This would resultin the binary tree below: +-- D Turn in The source code The mainprogram that runs the tests. These tests should be hard-coded Twill run your programs and make modifications i test them Output generated by your tests.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/**
* The basic Node class representing
* a node in the Binary Tree, it holds value
* along with left and right node associated
* with it.
*/
public class Node {

    // The string value to be stored at this node
    private String value;

    // Its left child node
    private Node left;

    // Its right child node
    private Node right;

    /**
    * The constructor to create a leaf node
    * i.e. it holds the value but left-right children
    * are null.
    * @param value the value to be stored.
    */
    public Node(String value) {
       this.value = value;
       this.left = null;
       this.right = null;
    }

    /**
    * The constructor to create a node with...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$20.00 $10.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats