Suppose an interface Visitor has a single method

void visit(Object obj)

Supply methods

void inOrder(Visitor v)
void preOrder(Visitor v)
void postOrder(Visitor v)

to the BinarySearchTree class. These methods should visit the tree nodes in the specified traversal order and apply the visit method to the data of the visited node.

Complete the following file:

BinarySearchTree.java

Use the following files:

Visitor.java

public interface Visitor
{
   public void visit(Object obj);
}

VisitorTester.java

public class VisitorTester
{
   public static void main(String[] args)
   {
      BinarySearchTree t = new BinarySearchTree();
      t.add("R");
      t.add("J");
      t.add("T");
      t.add("D");
      t.add("H");
      // ( ( ( . D ( . H . ) ) J . ) R ( . T . ) )

      class PrintVisitor implements Visitor
      {
         public void visit(Object o)
         {
            System.out.print(o);
         }
      }

      Visitor v = new PrintVisitor();
      t.inOrder(v);
      System.out.println();
      System.out.println("Expected: DHJRT");
      t.preOrder(v);
      System.out.println();
      System.out.println("Expected: RJDHT");
      t.postOrder(v);
      System.out.println();
      System.out.println("Expected: HDJTR");
   }
}