public class ArrayBasedAdjacencyListGraph extends java.lang.Object implements ArrayBasedGraph
Modifier and Type | Field and Description |
---|---|
private int[] |
degrees |
private static int |
maxDegree |
private int[][] |
neighbors |
Constructor and Description |
---|
ArrayBasedAdjacencyListGraph(int n)
Create a graph with n vertices (with a given maximum vertex degree)
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(int u,
int v)
Add an edge from vertex u to vertex v
|
boolean |
adjacent(int u,
int v)
Check whether there is an edge from u to v
|
int |
degree(int v)
Return the degree of a vertex
|
int[][] |
getEdges()
Return the list of all edges in the graph
|
java.util.Collection<java.lang.Integer> |
neighbors(int v)
Return the list of neighbors of a vertex
|
void |
removeEdge(int u,
int v) |
int |
sizeVertices()
Give the number of vertices
|
private int[][] neighbors
private int[] degrees
private static final int maxDegree
public ArrayBasedAdjacencyListGraph(int n)
n
- the number of verticespublic void addEdge(int u, int v)
addEdge
in interface ArrayBasedGraph
u
- first extremity of an edgev
- second extremity of an edgepublic void removeEdge(int u, int v)
removeEdge
in interface ArrayBasedGraph
public boolean adjacent(int u, int v)
adjacent
in interface ArrayBasedGraph
u
- first extremity of an edgev
- second extremity of an edgepublic int degree(int v)
degree
in interface ArrayBasedGraph
v
- the index of a vertexpublic java.util.Collection<java.lang.Integer> neighbors(int v)
neighbors
in interface ArrayBasedGraph
v
- the index of a vertexpublic int[][] getEdges()
getEdges
in interface ArrayBasedGraph
v
- the index of a vertexpublic int sizeVertices()
sizeVertices
in interface ArrayBasedGraph