/** Source code example for "A Practical Introduction to Data Structures and Algorithm Analysis, 3rd Edition (Java)" by Clifford A. Shaffer Copyright 2008-2011 by Clifford A. Shaffer */ public class GenTreeImpl implements GenTree { private GTNodeImpl rt; public GenTreeImpl() { rt = null; } public void clear() { rt = null; } public GTNode root() { return rt; } public void newroot(E value, GTNode first, GTNode sib) { clear(); rt = new GTNodeImpl(value, null, (GTNodeImpl)first, (GTNodeImpl)sib); if (first != null) first.setParent(rt); if (sib != null) sib.setParent(rt); } public void newleftchild(E value) { GTNodeImpl temp = new GTNodeImpl(value, rt, null, rt.leftmostChild()); rt.insertFirst(temp); } }