import net.datastructures.*; class tryBinaryTree1 { public static void main(String [] args){ LinkedBinaryTree BT1=new LinkedBinaryTree(); BT1.addRoot(" node0 "); BTNode r= (BTNode) BT1.root(); BT1.insertLeft(r," node1 "); BT1.insertRight(r," node2 "); BT1.insertLeft(BT1.left(BT1.root())," node3 "); BT1.insertRight(BT1.left(BT1.root())," node4 "); BT1.insertRight(BT1.left(BT1.left(BT1.root()))," node5 "); BT1.insertLeft(BT1.right(BT1.left(BT1.root()))," node6 "); java.util.Iterator BTIt= BT1.positions(); System.out.println(" node\t type\t\tleft children\tright children\tcomment"); while (BTIt.hasNext() ) { BTNode p1=(BTNode) BTIt.next(); System.out.print(p1.element()+"\t"); if(BT1.isInternal(p1)) { System.out.print(" Internal"+"\t"); if(BT1.hasLeft(p1)) System.out.print(BT1.left(p1).element()+"\t\t"); else System.out.print("\t\t"); if(BT1.hasRight(p1)) System.out.print(BT1.right(p1).element()); } else { System.out.print(" External"+"\t"); } if(BT1.isRoot(p1)) {System.out.print("\t \tRoot"); } System.out.println(); } System.out.println("\nThe nodes in in-order traversal are : "); InOrder((BTNode) BT1.root()); System.out.println("\nThe nodes in preorder traversal are : "); preOrder((BTNode) BT1.root()); System.out.println("\nThe nodes in postorder traversal are : "); postOrder((BTNode) BT1.root()); } static void InOrder(BTNode n1 ) { if(n1 !=null) { BTNode left1=(BTNode) n1.getLeft(); BTNode right1=(BTNode) n1.getRight(); InOrder(left1); System.out.print(n1.element()+ "\t"); InOrder(right1); } } static void preOrder(BTNode n1 ) { if(n1 !=null) { BTNode left1=(BTNode) n1.getLeft(); BTNode right1=(BTNode) n1.getRight(); System.out.print(n1.element()+ "\t"); preOrder(left1); preOrder(right1); } } static void postOrder(BTNode n1 ) { if(n1 !=null) { BTNode left1=(BTNode) n1.getLeft(); BTNode right1=(BTNode) n1.getRight(); postOrder(left1); postOrder(right1); System.out.print(n1.element()+ "\t"); } } }