|
datastructures | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.datastructures.VectorCompleteBinaryTree
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| Nested Class Summary | |
protected static class |
VectorCompleteBinaryTree.VectorNode
Nested class for a vector-based complete binary tree node. |
| Field Summary | |
protected Vector |
T
|
| Constructor Summary | |
VectorCompleteBinaryTree()
default constructor |
|
| Method Summary | |
Position |
add(Object e)
Add an element just after the last node (in a level numbering). |
protected VectorCompleteBinaryTree.VectorNode |
checkPosition(Position v)
Determine whether v is a valid node. |
Iterator |
children(Position v)
Returns an iterator of the children of v. |
Iterator |
elements()
Returns an iterator of the elements stored at all nodes in the tree. |
boolean |
hasLeft(Position v)
Returns whether v has a left child. |
boolean |
hasRight(Position v)
Returns whether v has a right child. |
protected int |
inorderPositions(Position v,
List pos,
int i)
Fills a list according to an inorder traversal. |
boolean |
isEmpty()
Returns whether the tree is empty. |
boolean |
isExternal(Position v)
Returns whether v is an external node. |
boolean |
isInternal(Position v)
Returns whether v is an internal node. |
boolean |
isRoot(Position v)
Returns whether v is the root node. |
Position |
left(Position v)
Returns the left child of v. |
Position |
parent(Position v)
Returns the parent of v. |
Iterator |
positions()
Returns an iterator of all nodes in the tree. |
Object |
remove()
Removes and returns the element at the last node. |
Object |
replace(Position v,
Object o)
Replaces the element at v. |
Position |
right(Position v)
Returns the right child of v. |
Position |
root()
Returns the root of the tree. |
Position |
sibling(Position v)
Returns the sibling of v. |
int |
size()
Returns the number of (internal and external) nodes. |
void |
swapElements(Position v,
Position w)
Swaps the elements at two nodes. |
String |
toString()
Returns a String representing this complete binary tree. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected Vector T
| Constructor Detail |
public VectorCompleteBinaryTree()
| Method Detail |
public int size()
size in interface Treepublic boolean isEmpty()
isEmpty in interface Tree
public boolean isInternal(Position v)
throws InvalidPositionException
isInternal in interface TreeInvalidPositionException
public boolean isExternal(Position v)
throws InvalidPositionException
isExternal in interface TreeInvalidPositionException
public boolean isRoot(Position v)
throws InvalidPositionException
isRoot in interface TreeInvalidPositionException
public boolean hasLeft(Position v)
throws InvalidPositionException
hasLeft in interface BinaryTreeInvalidPositionException
public boolean hasRight(Position v)
throws InvalidPositionException
hasRight in interface BinaryTreeInvalidPositionException
public Position root()
throws EmptyTreeException
root in interface TreeEmptyTreeException
public Position left(Position v)
throws InvalidPositionException,
BoundaryViolationException
left in interface BinaryTreeInvalidPositionException
BoundaryViolationException
public Position right(Position v)
throws InvalidPositionException
right in interface BinaryTreeInvalidPositionException
public Position parent(Position v)
throws InvalidPositionException,
BoundaryViolationException
parent in interface TreeInvalidPositionException
BoundaryViolationException
public Iterator children(Position v)
throws InvalidPositionException
children in interface TreeInvalidPositionExceptionpublic Iterator positions()
positions in interface Tree
public Object replace(Position v,
Object o)
throws InvalidPositionException
replace in interface TreeInvalidPositionExceptionpublic Position add(Object e)
add in interface CompleteBinaryTree
public Object remove()
throws EmptyTreeException
remove in interface CompleteBinaryTreeEmptyTreeException
protected VectorCompleteBinaryTree.VectorNode checkPosition(Position v)
throws InvalidPositionException
InvalidPositionException
protected int inorderPositions(Position v,
List pos,
int i)
throws InvalidPositionException
InvalidPositionException
public Position sibling(Position v)
throws InvalidPositionException,
BoundaryViolationException
InvalidPositionException
BoundaryViolationException
public void swapElements(Position v,
Position w)
throws InvalidPositionException
InvalidPositionExceptionpublic Iterator elements()
elements in interface Treepublic String toString()
|
datastructures | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||