Constructor and Description |
---|
AdjacencyListGraph()
Default constructor that creates an empty graph
|
Modifier and Type | Method and Description |
---|---|
boolean |
areAdjacent(Vertex<V> u,
Vertex<V> v)
Test whether two vertices are adjacent
|
int |
degree(Vertex<V> v)
Return the degree of a given vertex
|
java.lang.Iterable<Edge<E>> |
edges()
Return an iterator over the edges of the graph
|
Vertex<V>[] |
endVertices(Edge<E> e)
Return the endvertices of a edge in an array of length 2
|
java.lang.Iterable<Edge<E>> |
incidentEdges(Vertex<V> v)
Return an iterator over the edges incident on a vertex
|
Edge<E> |
insertEdge(Vertex<V> v,
Vertex<V> w,
E o)
Insert and return a new edge with a given element between two
vertices
|
Vertex<V> |
insertVertex(V o)
Insert and return a new vertex with a 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)
Return the other endvertex of an incident edge
|
E |
removeEdge(Edge<E> e)
Remove an edge and return its element
|
V |
removeVertex(Vertex<V> v)
Remove a vertex and all its incident edges and return the
element stored at the removed vertex
|
E |
replace(Edge<E> p,
E o)
Replaces the element of a given edge with a new element and
returns the old element
|
java.lang.Object |
replace(Position p,
java.lang.Object o)
Replace the element a given position (vertex or edge) with a new
element and return the old element
|
V |
replace(Vertex<V> p,
V o)
Replaces the element of a given vertex with a new element and
returns the old element
|
java.lang.String |
toString()
Returns a string representation of the vertex and edge lists,
separated by a newline.
|
java.lang.Iterable<Vertex<V>> |
vertices()
Return an iterator over the vertices of the graph
|
public AdjacencyListGraph()
public boolean areAdjacent(Vertex<V> u, Vertex<V> v) throws InvalidPositionException
areAdjacent
in interface Graph<V,E>
InvalidPositionException
public Vertex<V>[] endVertices(Edge<E> e) throws InvalidPositionException
endVertices
in interface Graph<V,E>
InvalidPositionException
public java.lang.Iterable<Edge<E>> incidentEdges(Vertex<V> v) throws InvalidPositionException
incidentEdges
in interface Graph<V,E>
InvalidPositionException
public Edge<E> insertEdge(Vertex<V> v, Vertex<V> w, E o) throws InvalidPositionException
insertEdge
in interface Graph<V,E>
InvalidPositionException
public Vertex<V> insertVertex(V o)
insertVertex
in interface Graph<V,E>
public int numEdges()
Graph
public int numVertices()
Graph
numVertices
in interface Graph<V,E>
public Vertex<V> opposite(Vertex<V> v, Edge<E> e) throws InvalidPositionException
opposite
in interface Graph<V,E>
InvalidPositionException
public E removeEdge(Edge<E> e) throws InvalidPositionException
removeEdge
in interface Graph<V,E>
InvalidPositionException
public V removeVertex(Vertex<V> v) throws InvalidPositionException
removeVertex
in interface Graph<V,E>
InvalidPositionException
public E replace(Edge<E> p, E o) throws InvalidPositionException
Graph
replace
in interface Graph<V,E>
InvalidPositionException
public java.lang.Object replace(Position p, java.lang.Object o) throws InvalidPositionException
InvalidPositionException
public V replace(Vertex<V> p, V o) throws InvalidPositionException
Graph
replace
in interface Graph<V,E>
InvalidPositionException
public java.lang.String toString()
toString
in class java.lang.Object