Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!