public abstract class Tree // Java 1.1 or later { public abstract Object contents(); // These public abstract Tree subTree(int i); // operations public abstract int fanOut(); // define public abstract boolean isEmpty(); // Tree-ness -- L.Allison. // ... // stuff omitted ... // ... private class Prefix implements Enumeration // see java.util { private Stack stck = new Stack(); // uses an explicit Stack public Prefix() { if(!Tree.this.isEmpty()) stck.push(Tree.this); }/*constructor*/ public boolean hasMoreElements() // ?more to enumerate? { return ! stck.empty(); } public Object nextElement() // next in prefix order { Tree t = (Tree)stck.peek(); stck.pop(); for(int i = t.fanOut() - 1; i >= 0; i--) { Tree ti = t.subTree(i); if(!ti.isEmpty()) // push each subtree stck.push(ti); } return t.contents(); } }//Prefix class public Enumeration prefix() // e.g. e = new T.prefix(); { return new Prefix(); } // ... // stuff omitted ... // ... }//Tree class // L. Allison, Computer Science and Software Engineering, Monash University