|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The interface describing all Graph objects. Graphs are collections of vertices connected by a set of edges. Edges may or may not be directed. Portions of the graph may be marked visited to support iterative algorithms. Iteration is provided over vertices, edges, and vertices adjacent to a particular vertex
Example usage:
To visit all of the vertices reachable from a given vertex we could use the following:
static void reachableFrom(Graph
g, Object vertexLabel) { g.visit(vertexLabel)
; // visit this vertex // recursively visit unvisited neighbor vertices Iterator ni = g.neighbors(vertexLabel)
; while (ni.hasNext()) { Object neighbor = ni.next(); // adjacent node label if (!g.isVisited(neighbor)
x) { reachableFrom(g,neighbor); // depth-first search } } }
GraphList
,
GraphMatrix
Method Summary | |
void |
add(Object label)
Add a vertex to the graph |
void |
addEdge(Object vtx1,
Object vtx2,
Object label)
Add an edge between two vertices within the graph. |
void |
clear()
Remove all vertices (and thus, edges) of the graph. |
boolean |
contains(Object label)
Test for vertex membership. |
boolean |
containsEdge(Object vLabel1,
Object vLabel2)
Test for edge membership. |
int |
degree(Object label)
Determine out degree of vertex. |
int |
edgeCount()
Determine the number of edges in graph. |
Iterator |
edges()
Construct an iterator over all edges. |
Object |
get(Object label)
Get reference to actual label of vertex. |
Edge |
getEdge(Object label1,
Object label2)
Get reference to actual edge. |
boolean |
isDirected()
Determine if graph is directed. |
boolean |
isEmpty()
Determine if graph is empty. |
boolean |
isVisited(Object label)
Return visited flag of vertex. |
boolean |
isVisitedEdge(Edge e)
Return visited flag of edge. |
Iterator |
iterator()
Construct vertex iterator. |
Iterator |
neighbors(Object label)
Construct an adjacent vertex iterator. |
Object |
remove(Object label)
Remove a vertex from the graph. |
Object |
removeEdge(Object vLabel1,
Object vLabel2)
Remove possible edge between vertices labeled vLabel1 and vLabel2. |
void |
reset()
Clear visited flags of edges and vertices. |
int |
size()
Determine number of vertices within graph. |
boolean |
visit(Object label)
Test and set visited flag of vertex |
boolean |
visitEdge(Edge e)
Test and set visited flag of edge. |
Methods inherited from interface structure.Structure |
elements, values |
Method Detail |
public void add(Object label)
add
in interface Structure
label
- Label of the vertex; should be non-nullpublic void addEdge(Object vtx1, Object vtx2, Object label)
vtx1
- First (or source, if directed) vertex.vtx2
- Second (or destination, if directed) vertex.label
- Label associated with the edge.public Object remove(Object label)
remove
in interface Structure
label
- The label of the vertex within the graph.public Object removeEdge(Object vLabel1, Object vLabel2)
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.public Object get(Object label)
label
- The label of the vertex sought.public Edge getEdge(Object label1, Object label2)
label1
- The first (or source, if directed) vertex.label2
- The second (or destination, if directed) vertex.public boolean contains(Object label)
contains
in interface Structure
label
- The label of the vertex sought.public boolean containsEdge(Object vLabel1, Object vLabel2)
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.public boolean visit(Object label)
label
- Label of vertex to be visited.public boolean visitEdge(Edge e)
e
- Edge object that is part of graph.public boolean isVisited(Object label)
label
- Label of vertex.public boolean isVisitedEdge(Edge e)
e
- Edge of graph to be considered.public void reset()
public int size()
size
in interface Structure
public int degree(Object label)
label
- Label associated with vertex.public int edgeCount()
public Iterator iterator()
iterator
in interface Structure
public Iterator neighbors(Object label)
label
- Label of the vertex.public Iterator edges()
public void clear()
clear
in interface Structure
public boolean isEmpty()
isEmpty
in interface Structure
public boolean isDirected()
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |