// Source code example for "A Practical Introduction // to Data Structures and Algorithm Analysis" // by Clifford A. Shaffer, Prentice Hall, 1998. // Copyright 1998 by Clifford A. Shaffer // A simple implementation for general trees. // This does not really address the thornier general tree // implementation issues, but it does is let you attach a couple // of trees together, and it is possible to build any tree. public class GenTreeImpl implements GenTree { private GTNode rt; public GenTreeImpl() { rt = null; } public void clear() { rt = null; } public GTNode root() { return rt; } public void newroot(Object value, GTNode first, GTNode sib) { clear(); rt = new GTNodeImpl(value, null, first, sib); if (first != null) first.setParent(rt); if (sib != null) sib.setParent(rt); } public void newleftchild(Object value) { GTNodeImpl temp = new GTNodeImpl(value, rt, null, rt.leftmost_child()); rt.insert_first(temp); } }