public class VectorCompleteBinaryTree implements CompleteBinaryTree {
protected Vector T; // vector of elements stored in the tree
/** Nested class for a vector-based complete binary tree node. */
protected static class VectorNode implements Position {
Object element; // element stored at this position
int index; // index of this position in the vector
public VectorNode(Object elt, int i) {
element = elt;
index = i;
}
public Object element() { return element; }
public int index() { return index; }
public Object setElement(Object elt) {
Object temp = element;
element = elt;
return temp;
}
}
/** default constructor */
public VectorCompleteBinaryTree() {
T = new ArrayVector();
T.insertAtRank(0,null); // the location at rank 0 is deliberately empty
}
/** Returns the number of (internal and external) nodes. */
public int size() { return T.size()-1; }
/** Returns whether the tree is empty. */
public boolean isEmpty() { return (size()==0); }