/* * TreeIn.java * * */ import net.datastructures.*; public class TreeInExample1 { static int order; /** Creates a new instance of TreeIn */ public static void TreeIn(LinkedBinaryTree t, Position p) { if (t.hasLeft(p)) { TreeIn(t, t.left(p)); } MyData1 data = (MyData1)p.element(); System.out.println("The Inorder of "+data.A+ " is "+ order); data.B = order; order++; if (t.hasRight(p)) { TreeIn(t, t.right(p)); } } public static void main(String[] args) { LinkedBinaryTree t = new LinkedBinaryTree(); Position parent; /* generate a tree t, insert 9 nodes */ t.addRoot(new MyData1('A')); parent = t.root(); t.insertLeft(parent, new MyData1('B')); t.insertRight(parent, new MyData1('C')); parent = t.left(t.root()); t.insertLeft(parent, new MyData1('D')); t.insertRight(parent, new MyData1('E')); parent = t.right(t.root()); t.insertLeft(parent, new MyData1('F')); t.insertRight(parent, new MyData1('G')); parent = t.right(t.left(t.root())); t.insertLeft(parent, new MyData1('H')); t.insertRight(parent, new MyData1('I')); /* print the structure of tree t */ MyData1.printTree(t); /* Inorder tranversal of tree t */ order = 1; TreeIn (t, t.root()); } }