// Tree1.java // Children are kept in an array. Upward and downward pointers. // public class Tree1 { private T label; private Tree1 parent; private Tree1[] children; // Array of children private int numChildren = 0; // Number of children // Constructor public Tree1(T l, Tree1[] c) { label=l; children = c; } // getters public T getLabel() { return label; } public Tree1 getParent() { return parent; } public Tree1[] getChildren() { return children; } public int getNumChildren() { return numChildren; } // Add node C as a child of this. public void addChild(Tree1 c) { if (numChildren < children.length) { children[numChildren] = c; numChildren++; c.parent = this; } } public void displayPreorder() { displayPreorder1(0); } public void displayPreorder1(int indent) { for (int I = 0; I < indent; I++) System.out.print(" "); System.out.println(label.toString()); for (int I=0; I < numChildren; I++) children[I].displayPreorder1(indent+3); } public void displayPostorder() { displayPostorder1(0); } public void displayPostorder1(int indent) { for (int I=0; I < numChildren; I++) children[I].displayPostorder1(indent+3); for (int I = 0; I < indent; I++) System.out.print(" "); System.out.println(label.toString()); } }