L - type of vertex labels in this graph, must be immutablepublic interface Graph<L>
L when compared
using the equals method.
Edges are directed and have a positive weight of type int.
PS2 instructions: this is a required ADT interface. You MUST NOT change the specifications or add additional methods.
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(L vertex)
Add a vertex to this graph.
|
static <L> Graph<L> |
empty()
Create an empty graph.
|
boolean |
remove(L vertex)
Remove a vertex from this graph; any edges to or from the vertex are
also removed.
|
int |
set(L source,
L target,
int weight)
Add, change, or remove a weighted directed edge in this graph.
|
Map<L,Integer> |
sources(L target)
Get the source vertices with directed edges to a target vertex and the
weights of those edges.
|
Map<L,Integer> |
targets(L source)
Get the target vertices with directed edges from a source vertex and the
weights of those edges.
|
Set<L> |
vertices()
Get all the vertices in this graph.
|
static <L> Graph<L> empty()
L - type of vertex labels in the graph, must be immutableboolean add(L vertex)
vertex - label for the new vertexint set(L source, L target, int weight)
source - label of the source vertextarget - label of the target vertexweight - nonnegative weight of the edgeboolean remove(L vertex)
vertex - label of the vertex to removeSet<L> vertices()
Map<L,Integer> sources(L target)
target - a labelMap<L,Integer> targets(L source)
source - a label