Question: Each of these files asks you to write a method that processes binary tree data structures from the binary tree package. Carefully read the description

Each of these files asks you to write a method that processes binary tree data structures from the binary tree package. Carefully read the description of each method and then implement the method. Each of those files contains a main() method that provides a simple test of the method you need to write. These tests are not very complex and they may not be enough to verify that your implementation is correct. You should think about and write your own tests and add them to the main() method.

/*

*/

import binarytree.*;

/** A program that tests the addStringBTrees() and addIntegerBTrees() methods. */ public class AddBTrees { /** Return a binary tree that is the "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 tree of size 1 (a leaf tree) is the leaf tree.

The sum of two trees of size 1 (two leaf trees) is a tree of size 1 (a leaf tree) whose data element is the sum of the data elements from the two leaf trees.

The sum of two 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 with the compareBTrees() method). */ public static BTreeAbstract addStringBTrees(BTree btree1, BTree btree2) {

}

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

This method is define 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!