Constructor and Description |
---|
AdjacencyMatrix()
Creates a new adjacency matrix with an initial row capacity of ten.
|
AdjacencyMatrix(int capacity)
Creates a new adjacency matrix.
|
Modifier and Type | Method and Description |
---|---|
void |
add(E edge)
Adds an edge to the adjacency matrix.
|
E |
get(int v1,
int v2)
Gets the edge between the two vertices.
|
E |
get(V v1,
V v2)
Gets the edge between the two vertices.
|
java.util.List<E> |
getAll(int v1,
int v2)
Gets a list of all edges between the two vertices.
|
java.util.List<E> |
getAll(V v1,
V v2)
Gets a list of all edges between the two vertices.
|
void |
remove(E edge)
Removes an edge from the adjacency matrix.
|
public AdjacencyMatrix()
public AdjacencyMatrix(int capacity)
capacity
- the initial row capacitypublic void add(E edge) throws java.lang.NullPointerException
edge
- the edgejava.lang.NullPointerException
- public void remove(E edge) throws java.lang.NullPointerException
edge
- the edgejava.lang.NullPointerException
- public E get(int v1, int v2)
G = (V, E)
be a graph with V
as the set of vertices and E
as the set of edges and m
be the
adjacency matrix. then m(i,k) = edge
if (i,k)
is an element of E
and m(i,k) = null
if (i,k)
is not
an element of E
.v1
- the id of the first vertexv2
- the id of the second vertexnull
if there is no edge between v1 and v2 ((v1,v2)
is not an element of E
)public java.util.List<E> getAll(int v1, int v2)
getAll(v1,v2) == getAll(v2,v1)
otherwise
one has getAll(v1,v2) != getAll(v2,v1)
.v1
- the id of the first vertexv2
- the id of the second vertexnull
if there is no edge between the verticesget(int, int)
public E get(V v1, V v2) throws java.lang.NullPointerException
G = (V, E)
be a graph with V
as the set of vertices and E
as the set of edges and m
be the
adjacency matrix. then m(i,k) = edge
if (i,k)
is an element of E
and m(i,k) = null
if (i,k)
is not
an element of E
.v1
- the first vertexv2
- the second vertexnull
if there is no edge between v1 and v2 ((v1,v2)
is not an element of E
)java.lang.NullPointerException
- public java.util.List<E> getAll(V v1, V v2) throws java.lang.NullPointerException
getAll(v1,v2) == getAll(v2,v1)
otherwise
one has getAll(v1,v2) != getAll(v2,v1)
.v1
- the first vertexv2
- the second vertexnull
if there is no edge between the verticesjava.lang.NullPointerException
- get(Vertex, Vertex)