/** Returns an iterator of the elements stored at the nodes */ public Iterator elements() { Iterator positer = positions(); List elements = new NodeList(); for (int i = 0; i < size; i++) elements.insertLast(((Position) positer.next()).element()); return elements.elements(); // An iterator of elements } /** Replaces the element at a node. */ public Object replace(Position v, Object o) throws InvalidPositionException { BTPosition vv = checkPosition(v); Object temp = v.element(); vv.setElement(o); return temp; } // Additional accessor method /** Return the sibling of a node */ public Position sibling(Position v) throws InvalidPositionException, BoundaryViolationException { try { Position p = parent(v); Position lc = left(p); if (v == lc) return right(p); else return lc; } catch(BoundaryViolationException e) { throw new BoundaryViolationException("Node has no sibling"); } } // Additional update methods /** Inserts a left child at a given node. */ public Position insertLeft(Position v, Object e) throws InvalidPositionException { if (hasLeft(v)) throw new InvalidPositionException("Node already has a left child"); BTPosition vv = (BTPosition)v; BTPosition ww = createNode(e, vv, null, null); vv.setLeft(ww); size++; return ww; }