|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
This is the simplest useful directed graph interface. It mainly just has outIncidentEdges(). That is enough to support traversal algorithms like DFS, BFS, and Dijkstra's algorithm. The interface is missing many graph methods proposed in the textbook's section 12.1.1 -- to start with, inIncidentEdges() -- but it could be extended to have those methods.
An implementation of just this simple interface doesn't have to store much data. For example, it is not necessary to store a list of all vertices. Many algorithms don't require the class to maintain such a list. Instead, the algorithm itself may store one or more of the vertices created and returned by insertVertex(); for example, a start vertex may be enough.
The name "Digraph" is a common abbreviation for "directed graph."
| Method Summary | |
graph.DirectedEdge |
insertDirectedEdge(graph.Vertex from,
graph.Vertex to,
java.lang.Object element)
Adds a new directed edge from one vertex to another. |
void |
insertReverseOf(graph.DirectedEdge e)
Convenience method: Add the reverse of the given edge, with the same element. |
graph.Vertex |
insertVertex(java.lang.Object element)
Insert and return a new vertex. |
int |
numEdges()
Return the size of the graph (number of edges, m). |
int |
numVertices()
Return the order of the graph (number of vertices, n). |
java.util.Iterator |
outIncidentEdges(graph.Vertex v)
Return an iterator over all the directed edges from a vertex. |
| Method Detail |
public int numVertices()
public int numEdges()
public java.util.Iterator outIncidentEdges(graph.Vertex v)
public graph.Vertex insertVertex(java.lang.Object element)
element - the element stored at the vertex.
public graph.DirectedEdge insertDirectedEdge(graph.Vertex from,
graph.Vertex to,
java.lang.Object element)
throws InvalidPositionException
element - the element stored on the edge.
InvalidPositionException - if the implementation detects that one
of the vertices is not actually in this graph.public void insertReverseOf(graph.DirectedEdge e)
insertReverseOf(insertDirectedEdge(from, to, element));
This is convenient if from, to, or element is a complicated
expression.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||