|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Graph<V,E>
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(V label)
Add a vertex to the graph |
void |
addEdge(V vtx1,
V vtx2,
E label)
Add an edge between two vertices within the graph. |
void |
clear()
Remove all vertices (and thus, edges) of the graph. |
boolean |
contains(V label)
Test for vertex membership. |
boolean |
containsEdge(V vLabel1,
V vLabel2)
Test for edge membership. |
int |
degree(V label)
Determine out degree of vertex. |
int |
edgeCount()
Determine the number of edges in graph. |
java.util.Iterator<Edge<V,E>> |
edges()
Construct an iterator over all edges. |
V |
get(V label)
Get reference to actual label of vertex. |
Edge<V,E> |
getEdge(V label1,
V label2)
Get reference to actual edge. |
boolean |
isDirected()
Determine if graph is directed. |
boolean |
isEmpty()
Determine if graph is empty. |
boolean |
isVisited(V label)
Return visited flag of vertex. |
boolean |
isVisitedEdge(Edge<V,E> e)
Return visited flag of edge. |
java.util.Iterator<V> |
iterator()
Construct vertex iterator. |
java.util.Iterator<V> |
neighbors(V label)
Construct an adjacent vertex iterator. |
V |
remove(V label)
Remove a vertex from the graph. |
E |
removeEdge(V vLabel1,
V 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(V label)
Test and set visited flag of vertex |
boolean |
visitEdge(Edge<V,E> e)
Test and set visited flag of edge. |
Methods inherited from interface structure.Structure |
---|
elements, values |
Method Detail |
---|
void add(V label)
add
in interface Structure<V>
label
- Label of the vertex; should be non-nullvoid addEdge(V vtx1, V vtx2, E label)
vtx1
- First (or source, if directed) vertex.vtx2
- Second (or destination, if directed) vertex.label
- Label associated with the edge.V remove(V label)
remove
in interface Structure<V>
label
- The label of the vertex within the graph.
E removeEdge(V vLabel1, V vLabel2)
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.
V get(V label)
label
- The label of the vertex sought.
Edge<V,E> getEdge(V label1, V label2)
label1
- The first (or source, if directed) vertex.label2
- The second (or destination, if directed) vertex.
boolean contains(V label)
contains
in interface Structure<V>
label
- The label of the vertex sought.
boolean containsEdge(V vLabel1, V vLabel2)
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.
boolean visit(V label)
label
- Label of vertex to be visited.
boolean visitEdge(Edge<V,E> e)
e
- Edge object that is part of graph.
boolean isVisited(V label)
label
- Label of vertex.
boolean isVisitedEdge(Edge<V,E> e)
e
- Edge of graph to be considered.
void reset()
int size()
size
in interface Structure<V>
int degree(V label)
label
- Label associated with vertex.
int edgeCount()
java.util.Iterator<V> iterator()
iterator
in interface java.lang.Iterable<V>
iterator
in interface Structure<V>
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
java.util.Iterator<V> neighbors(V label)
label
- Label of the vertex.
java.util.Iterator<Edge<V,E>> edges()
void clear()
clear
in interface Structure<V>
boolean isEmpty()
isEmpty
in interface Structure<V>
boolean isDirected()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |