Constructor and Description |
---|
AdjacencyMapGraph(boolean directed)
Constructs an empty graph.
|
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 for which vertex v is the origin.
|
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.
|
String |
toString()
Returns a string representation of the graph.
|
Iterable<Vertex<V>> |
vertices()
Returns the vertices of the graph as an iterable collection
|
public AdjacencyMapGraph(boolean directed)
public int numVertices()
numVertices
in interface Graph<V,E>
public Iterable<Vertex<V>> vertices()
public int numEdges()
public int outDegree(Vertex<V> v) throws IllegalArgumentException
outDegree
in interface Graph<V,E>
IllegalArgumentException
- if v is not a valid vertexpublic Iterable<Edge<E>> outgoingEdges(Vertex<V> v) throws IllegalArgumentException
outgoingEdges
in interface Graph<V,E>
IllegalArgumentException
- if v is not a valid vertexpublic int inDegree(Vertex<V> v) throws IllegalArgumentException
inDegree
in interface Graph<V,E>
IllegalArgumentException
- if v is not a valid vertexpublic Iterable<Edge<E>> incomingEdges(Vertex<V> v) throws IllegalArgumentException
incomingEdges
in interface Graph<V,E>
IllegalArgumentException
- if v is not a valid vertexpublic Edge<E> getEdge(Vertex<V> u, Vertex<V> v) throws IllegalArgumentException
getEdge
in interface Graph<V,E>
IllegalArgumentException
public Vertex<V>[] endVertices(Edge<E> e) throws IllegalArgumentException
endVertices
in interface Graph<V,E>
IllegalArgumentException
public Vertex<V> opposite(Vertex<V> v, Edge<E> e) throws IllegalArgumentException
opposite
in interface Graph<V,E>
IllegalArgumentException
public Vertex<V> insertVertex(V element)
insertVertex
in interface Graph<V,E>
public Edge<E> insertEdge(Vertex<V> u, Vertex<V> v, E element) throws IllegalArgumentException
insertEdge
in interface Graph<V,E>
IllegalArgumentException
- if u or v are invalid vertices, or if an edge already exists between u and v.public void removeVertex(Vertex<V> v) throws IllegalArgumentException
removeVertex
in interface Graph<V,E>
IllegalArgumentException
public void removeEdge(Edge<E> e) throws IllegalArgumentException
Graph
removeEdge
in interface Graph<V,E>
IllegalArgumentException