/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package trees; /** * * @author kvaradar */ public class MyTree implements Tree { private int size; private TreeNode root; public MyTree() { root = null; size = 0; } /* I have added the methods addRoot and addChild so that * I can construct a tree on which you can test the methods * you write. These two methods are not as robust as they * can be, but will do for this particular purpose. */ public Position addRoot(E e) { // Create a node with e, make it the root, and return the position TreeNode t = new TreeNode(e,null); root = t; size = 1; return t; } public Position addChild(Position v, E e) { // Create a node with e, add it as a child of v, and return new position TreeNode w = (TreeNode) v; TreeNode t = new TreeNode(e, w); w.addChild(t); size++; return t; } public int size() {return size;} }