All Packages Class Hierarchy This Package Previous Next Index
Class rpi.goldsd.graph.Tree
java.lang.Object
|
+----rpi.goldsd.graph.GraphBase
|
+----rpi.goldsd.graph.Tree
- public class Tree
- extends GraphBase
The Tree class is a subclass of the GraphBase class and
is used to represent a tree. A tree is a graph that adheres to the
following additional set of requirements:
- The graph must be connected.
- The graph must be acyclic.
- The tree must be rooted at a specified vertex.
- Version:
- 2.1, 5/12/98
- Author:
- David Goldschmidt
- See Also:
- GraphBase
-
root
- A reference to the root Vertex object of this tree.
-
Tree()
- Default constructor is not used, since a tree must, by definition,
have a root vertex.
-
Tree(String, int, int)
- Constructs a tree with the specified name, initial vertex hashtable
size, and initial edge hashtable size.
-
Tree(Tree)
- Constructs a tree by copying another tree.
-
Tree(Vertex)
- Constructs an unnamed tree with the specified root vertex.
-
Tree(Vertex, int, int)
- Constructs a tree with the specified root vertex, initial
vertex hashtable size and initial edge hashtable size.
-
Tree(Vertex, String)
- Constructs a tree with the specified root vertex and name.
-
Tree(Vertex, String, int, int)
- Constructs a tree with the specified root vertex, name,
initial vertex hashtable size, and initial edge hashtable size.
-
add(Edge, Vertex)
- Adds an edge and corresponding vertex to this tree.
-
clear()
- Removes all vertices and edges from this tree, except for the
root Vertex object.
-
clone()
- Clones this tree.
-
root()
- Returns a reference to the root vertex of this tree.
root
protected Vertex root
- A reference to the root Vertex object of this tree.
Tree
public Tree(Vertex root,
String name,
int vertexTableSize,
int edgeTableSize)
- Constructs a tree with the specified root vertex, name,
initial vertex hashtable size, and initial edge hashtable size.
- Parameters:
- root - the root vertex of this tree.
- name - the user-defined name of this tree.
- vertexTableSize - the initial hashtable size for the hashtable
used to contain the set of vertices.
- edgeTableSize - the initial hashtable size for the
hashtable used to contain the set of edges.
Tree
protected Tree(String name,
int vertexTableSize,
int edgeTableSize)
- Constructs a tree with the specified name, initial vertex hashtable
size, and initial edge hashtable size. Note that a root vertex is
not specified in this protected method; this method is used by the
clone() method of the Tree class.
- Parameters:
- name - the user-defined name of this tree.
- vertexTableSize - the initial hashtable size for the hashtable
used to contain the set of vertices.
- edgeTableSize - the initial hashtable size for the
hashtable used to contain the set of edges.
Tree
public Tree(Vertex root,
int vertexTableSize,
int edgeTableSize)
- Constructs a tree with the specified root vertex, initial
vertex hashtable size and initial edge hashtable size.
- Parameters:
- root - the root vertex of this tree.
- vertexTableSize - the initial hashtable size for the hashtable
used to contain the set of vertices.
- edgeTableSize - the initial hashtable size for the
hashtable used to contain the set of edges.
Tree
public Tree(Vertex root,
String name)
- Constructs a tree with the specified root vertex and name.
- Parameters:
- root - the root vertex of this tree.
- name - the user-defined name of this tree.
Tree
public Tree(Tree T)
- Constructs a tree by copying another tree.
- Parameters:
- T - the tree to copy.
Tree
public Tree(Vertex root)
- Constructs an unnamed tree with the specified root vertex.
- Parameters:
- root - the root vertex of this tree.
Tree
protected Tree()
- Default constructor is not used, since a tree must, by definition,
have a root vertex.
clone
public Object clone()
- Clones this tree.
- Returns:
- a new tree that is a clone of this tree.
- Overrides:
- clone in class GraphBase
root
public Vertex root()
- Returns a reference to the root vertex of this tree.
- Returns:
- a reference to the root vertex of this tree.
add
public void add(Edge E,
Vertex V) throws DuplicateElementException, InAnotherGraphException, VertexNotFoundException, IllegalArgumentException
- Adds an edge and corresponding vertex to this tree. To maintain
the properties of a tree, an edge and corresponding vertex must
be added as an atomic method. Adding an unattached vertex is
not allowed.
The given edge must have an endpoint vertex that exists in this
tree and another endpoint vertex that is the second argument V.
- Parameters:
- E - the edge to be added to this tree.
- V - the vertex to be added to this tree.
- Throws: IllegalArgumentException
- if the vertex and edge arguments
are not connected.
- Throws: DuplicateElementException
- if
the key of either the edge or the vertex to be added
is already present in the set of edges and vertices,
respectively.
- Throws: InAnotherGraphException
- if the
edge or vertex is already in a different graph.
- Throws: VertexNotFoundException
- if the
endpoint vertex that is to already exist in this
tree does not exist in this tree.
clear
public void clear()
- Removes all vertices and edges from this tree, except for the
root Vertex object.
- Overrides:
- clear in class GraphBase
All Packages Class Hierarchy This Package Previous Next Index