| 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.datastructures.ArrayListCompleteBinaryTree<E>
public class ArrayListCompleteBinaryTree<E>
A speedy implementation of the CompleteBinaryTree interface using
 a vector.  Within the vector, there is a null element at rank 0,
 the root of the tree at rank 1, and the rest of the tree is
 contained as follows.  If node n has rank i,
 then the left child of n will have rank 2*i,
 and the right child of n will have rank 2*i +
 1.  Traversing the contents of the vector in order of increasing
 rank yields a level-order traversal
BinaryTree, 
CompleteBinaryTree| Constructor Summary | |
|---|---|
ArrayListCompleteBinaryTree()
default constructor  | 
|
| Method Summary | |
|---|---|
 Position<E> | 
add(E e)
Adds an element just after the last node (in a level numbering).  | 
 java.lang.Iterable<Position<E>> | 
children(Position<E> v)
Returns an iterable collection of the children of v.  | 
 boolean | 
hasLeft(Position<E> v)
Returns whether v has a left child.  | 
 boolean | 
hasRight(Position<E> v)
Returns whether v has a right child.  | 
 boolean | 
isEmpty()
Returns whether the tree is empty.  | 
 boolean | 
isExternal(Position<E> v)
Returns whether v is an external node.  | 
 boolean | 
isInternal(Position<E> v)
Returns whether v is an internal node.  | 
 boolean | 
isRoot(Position<E> v)
Returns whether v is the root node.  | 
 java.util.Iterator<E> | 
iterator()
Returns an iterator of the elements stored at all nodes in the tree.  | 
 Position<E> | 
left(Position<E> v)
Returns the left child of v.  | 
 Position<E> | 
parent(Position<E> v)
Returns the parent of v.  | 
 java.lang.Iterable<Position<E>> | 
positions()
Returns an iterable collection of all the nodes in the tree.  | 
 E | 
remove()
Removes and returns the element at the last node.  | 
 E | 
replace(Position<E> v,
        E o)
Replaces the element at v.  | 
 Position<E> | 
right(Position<E> v)
Returns the right child of v.  | 
 Position<E> | 
root()
Returns the root of the tree.  | 
 Position<E> | 
sibling(Position<E> v)
Returns the sibling of v.  | 
 int | 
size()
Returns the number of (internal and external) nodes.  | 
 void | 
swapElements(Position<E> v,
             Position<E> w)
Swaps the elements at two nodes.  | 
 java.lang.String | 
toString()
Returns a String representing this complete binary tree.  | 
| Methods inherited from class java.lang.Object | 
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Constructor Detail | 
|---|
public ArrayListCompleteBinaryTree()
| Method Detail | 
|---|
public int size()
size in interface Tree<E>public boolean isEmpty()
isEmpty in interface Tree<E>
public boolean isInternal(Position<E> v)
                   throws InvalidPositionException
isInternal in interface Tree<E>InvalidPositionException
public boolean isExternal(Position<E> v)
                   throws InvalidPositionException
isExternal in interface Tree<E>InvalidPositionException
public boolean isRoot(Position<E> v)
               throws InvalidPositionException
isRoot in interface Tree<E>InvalidPositionException
public boolean hasLeft(Position<E> v)
                throws InvalidPositionException
hasLeft in interface BinaryTree<E>InvalidPositionException
public boolean hasRight(Position<E> v)
                 throws InvalidPositionException
hasRight in interface BinaryTree<E>InvalidPositionException
public Position<E> root()
                 throws EmptyTreeException
root in interface Tree<E>EmptyTreeException
public Position<E> left(Position<E> v)
                 throws InvalidPositionException,
                        BoundaryViolationException
left in interface BinaryTree<E>InvalidPositionException
BoundaryViolationException
public Position<E> right(Position<E> v)
                  throws InvalidPositionException
right in interface BinaryTree<E>InvalidPositionException
public Position<E> parent(Position<E> v)
                   throws InvalidPositionException,
                          BoundaryViolationException
parent in interface Tree<E>InvalidPositionException
BoundaryViolationException
public java.lang.Iterable<Position<E>> children(Position<E> v)
                                         throws InvalidPositionException
children in interface Tree<E>InvalidPositionExceptionpublic java.lang.Iterable<Position<E>> positions()
positions in interface Tree<E>
public E replace(Position<E> v,
                 E o)
          throws InvalidPositionException
replace in interface Tree<E>InvalidPositionExceptionpublic Position<E> add(E e)
add in interface CompleteBinaryTree<E>
public E remove()
         throws EmptyTreeException
remove in interface CompleteBinaryTree<E>EmptyTreeException
public Position<E> sibling(Position<E> v)
                    throws InvalidPositionException,
                           BoundaryViolationException
InvalidPositionException
BoundaryViolationException
public void swapElements(Position<E> v,
                         Position<E> w)
                  throws InvalidPositionException
InvalidPositionExceptionpublic java.util.Iterator<E> iterator()
iterator in interface Tree<E>public java.lang.String toString()
toString in class java.lang.Object
  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||