- public int numChildren() { return children.length; }
- public Iterable<Tree<T>> children() { return new ArrayIterator(children); }
- public Iterator<Tree<T>> iterator() { return new ArrayIterator(children); }
- public Tree<T> child(int i) { return children[i]; }
+
+ private Tree<T> lifted() { return children[children.length-1]; }
+
+ public int numChildren() {
+ return lift
+ ? (children.length-1)+lifted().numChildren()
+ : children.length;
+ }
+ public Iterable<Tree<T>> children() { return this; }
+ public Iterator<Tree<T>> iterator() {
+ return lift
+ ? new ConcatenateIterator(new ArrayIterator(children, 0, children.length-1),
+ children[children.length-1].iterator())
+ : new ArrayIterator(children);
+ }
+
+ public Tree<T> child(int i) {
+ return lift && i >= children.length-1
+ ? children[children.length-1].child(i-(children.length-1))
+ : children[i];
+ }