Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA - Please complete the addStringBTrees() and addIntegerBTrees() methods below: /* */ import binarytree.*; /** A program that tests the addStringBTrees() and addIntegerBTrees() methods. */

JAVA - Please complete the addStringBTrees() and addIntegerBTrees() methods below:

/*

*/

import binarytree.*;

/** A program that tests the addStringBTrees() and addIntegerBTrees() methods. */ public class AddBTrees { /** Return a binary tree that is the node-by-node "sum" of the two input trees of type String.

The sum of two empty trees is the empty tree.

The sum of an empty tree and a non-empty tree is the non-empty tree.

The sum of two non-empty trees is a tree whose root data element is the sum of the root data elements from the two trees.

The sum of two non-empty binary trees is defined recursively using the above three cases.

Notice that the result tree has a node at any position where at least one of the two input trees has a node. You might say that the result tree has the shape of the "union" of the two input trees (compare this with the CompareBTrees.compareBTrees() method). */ public static BTreeAbstract addStringBTrees(BTree btree1, BTree btree2) {

}

/** Return a binary tree that is the node-by-node "sum" of the two input trees of type Integer.

This method is defined similarly to addStringBTrees(). */ // Define addIntegerBTrees()...

// Simple test cases for addStringBTrees() and addIntegerBTrees(). public static void main(String[] args) { BTree btree1 = new LinkedBTree<>(1, new LinkedBTree<>(12), new LinkedBTree<>(123));

BTree btree2 = new LinkedBTree<>(4, new LinkedBTree<>(45), new LinkedBTree<>(456));

BTree btree3 = addIntegerBTrees(btree1, btree2);

System.out.println( btree1 ); System.out.println( btree2 ); System.out.println( btree3 ); BTree2dot.btree2dot(btree1, "btree1"); BTree2png.btree2png("btree1"); BTree2dot.btree2dot(btree2, "btree2"); BTree2png.btree2png("btree2"); BTree2dot.btree2dot(btree3, "btree3"); BTree2png.btree2png("btree3");

BTree btree4 = new LinkedBTree<>("a", new LinkedBTree<>("ab"), new LinkedBTree<>("abc"));

BTree btree5 = new LinkedBTree<>("x", new LinkedBTree<>("xy"), new LinkedBTree<>("xyz"));

BTree btree6 = addStringBTrees(btree4, btree5);

System.out.println( btree4 ); System.out.println( btree5 ); System.out.println( btree6 ); BTree2dot.btree2dot(btree4, "btree4"); BTree2png.btree2png("btree4"); BTree2dot.btree2dot(btree5, "btree5"); BTree2png.btree2png("btree5"); BTree2dot.btree2dot(btree6, "btree6"); BTree2png.btree2png("btree6"); } }

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_2

Step: 3

blur-text-image_3

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

What is patronage in terms of poitical machines

Answered: 1 week ago