public interface Graph<V,E>
Modifier and Type | Method and Description |
---|---|
Iterable<Edge<E>> |
edges()
Returns the edges of the graph as an iterable collection
|
Vertex<V>[] |
endVertices(Edge<E> e)
Returns the vertices of edge e as an array of length two.
|
Edge<E> |
getEdge(Vertex<V> u,
Vertex<V> v)
Returns the edge from u to v, or null if they are not adjacent.
|
Iterable<Edge<E>> |
incomingEdges(Vertex<V> v)
Returns an iterable collection of edges for which vertex v is the destination.
|
int |
inDegree(Vertex<V> v)
Returns the number of edges for which vertex v is the destination.
|
Edge<E> |
insertEdge(Vertex<V> u,
Vertex<V> v,
E element)
Inserts and returns a new edge between vertices u and v, storing given element.
|
Vertex<V> |
insertVertex(V element)
Inserts and returns a new vertex with the given element.
|
int |
numEdges()
Returns the number of edges of the graph
|
int |
numVertices()
Returns the number of vertices of the graph
|
Vertex<V> |
opposite(Vertex<V> v,
Edge<E> e)
Returns the vertex that is opposite vertex v on edge e.
|
int |
outDegree(Vertex<V> v)
Returns the number of edges leaving vertex v.
|
Iterable<Edge<E>> |
outgoingEdges(Vertex<V> v)
Returns an iterable collection of edges for which vertex v is the origin.
|
void |
removeEdge(Edge<E> e)
Removes an edge from the graph.
|
void |
removeVertex(Vertex<V> v)
Removes a vertex and all its incident edges from the graph.
|
Iterable<Vertex<V>> |
vertices()
Returns the vertices of the graph as an iterable collection
|
int numVertices()
int numEdges()
int outDegree(Vertex<V> v) throws IllegalArgumentException
IllegalArgumentException
- if v is not a valid vertexint inDegree(Vertex<V> v) throws IllegalArgumentException
IllegalArgumentException
- if v is not a valid vertexIterable<Edge<E>> outgoingEdges(Vertex<V> v) throws IllegalArgumentException
IllegalArgumentException
- if v is not a valid vertexIterable<Edge<E>> incomingEdges(Vertex<V> v) throws IllegalArgumentException
IllegalArgumentException
- if v is not a valid vertexEdge<E> getEdge(Vertex<V> u, Vertex<V> v) throws IllegalArgumentException
IllegalArgumentException
Vertex<V>[] endVertices(Edge<E> e) throws IllegalArgumentException
IllegalArgumentException
Vertex<V> opposite(Vertex<V> v, Edge<E> e) throws IllegalArgumentException
IllegalArgumentException
Vertex<V> insertVertex(V element)
Edge<E> insertEdge(Vertex<V> u, Vertex<V> v, E element) throws IllegalArgumentException
IllegalArgumentException
- if u or v are invalid vertices, or if an edge already exists between u and v.void removeVertex(Vertex<V> v) throws IllegalArgumentException
IllegalArgumentException
void removeEdge(Edge<E> e) throws IllegalArgumentException
IllegalArgumentException