import binaryTree.*; import binaryTree.visitor.*; import ordering.*; /** * Driver to test binary insertion/deletion and tree printing. * @author Dung X. Nguyen */ public class BiTreeClient1 { /** * @param args == null - not used. */ public static void main(String[] args) { Integer m0 = new Integer (0); Integer m7 = new Integer (-7); Integer i23 = new Integer (23); Integer m55 = new Integer (-55); Integer m16 = new Integer (-16); Integer m4 = new Integer (-4); Integer m9 = new Integer (-9); Integer m20 = new Integer (-20); IVisitor bstInserter = new BSTInserter (OrderInt.Singleton); IVisitor bstFinder = new BSTFinder (OrderInt.Singleton); BiTree t0 = new BiTree (); System.out.println ("t0 is empty:\n" + t0); System.out.println ("\nInserting " + m7); t0.execute (bstInserter, m7); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nInserting " + m0); t0.execute (bstInserter, m0); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nInserting " + i23); t0.execute (bstInserter, i23); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nInserting " + m55); t0.execute (bstInserter, m55); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nInserting " + m16); t0.execute (bstInserter, m16); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nInserting " + m4); t0.execute (bstInserter, m4); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nInserting " + m9); t0.execute (bstInserter, m9); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nInserting " + m20); t0.execute (bstInserter, m20); System.out.println ("\nt0 is now: \n" + t0); System.out.println ("\nTree for " + m16 + ":\n" + t0.execute (bstFinder, m16)); IDictionary bstDict = new BSTDictionary (OrderInt.Singleton); System.out.println ("\nStoring:" + m7 + "," + i23); bstDict.store (m7, i23); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nStoring:" + m0 + "," + i23); bstDict.store (m0, i23); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nStoring:" + i23 + "," + i23); bstDict.store (i23, i23); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nStoring:" + m55 + "," + i23); bstDict.store (m55, i23); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nStoring:" + m16 + "," + m7); bstDict.store (m16, m7); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nStoring:" + m4 + "," + m0); bstDict.store (m4, m0); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nRemoving:" + m0); bstDict.remove (m0); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nRemoving:" + m7); bstDict.remove (m7); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nRemoving:" + m4); bstDict.remove (m4); System.out.println ("\nbstDict is:\n" + bstDict); System.out.println ("\nRemoving (again):" + m4); bstDict.remove (m4); System.out.println ("\nbstDict is:\n" + bstDict); } }