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
}
/** 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
BTree
BTree
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
BTree
BTree
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
Get step-by-step solutions from verified subject matter experts
