public class ArrayBasedAdjacencyListGraph extends java.lang.Object implements ArrayBasedGraph
| Constructor and Description |
|---|
ArrayBasedAdjacencyListGraph(java.util.Collection<java.lang.Integer>[] nodes)
Create a graph from the adjacency lists
Each vertex stores the list of its neighbors (vertex indices)
Remarks:
-) the graph is assumed to be undirected, and each edge appears twice: (u,v) and (v,u)
-) vertex indices range from 0 to n-1
|
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
|
boolean |
checkCombinatorics()
Check whether the graph is combinatorially consistent
|
int |
degree(int v)
Return the degree of a vertex
|
int[][] |
getEdges()
Return the list of all (undirected) edges in the graph
(each edge does appear only once)
|
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
|
public ArrayBasedAdjacencyListGraph(int n)
n - the number of verticespublic ArrayBasedAdjacencyListGraph(java.util.Collection<java.lang.Integer>[] nodes)
nodes - an array containing (in the entry nodes[i]) the list of neighbors of vertex v_ipublic void addEdge(int u,
int v)
addEdge in interface ArrayBasedGraphu - first extremity of an edgev - second extremity of an edgepublic void removeEdge(int u,
int v)
removeEdge in interface ArrayBasedGraphpublic boolean adjacent(int u,
int v)
adjacent in interface ArrayBasedGraphu - first extremity of an edgev - second extremity of an edgepublic int degree(int v)
degree in interface ArrayBasedGraphv - the index of a vertexpublic java.util.Collection<java.lang.Integer> neighbors(int v)
neighbors in interface ArrayBasedGraphv - the index of a vertexpublic int[][] getEdges()
getEdges in interface ArrayBasedGraphpublic int sizeVertices()
sizeVertices in interface ArrayBasedGraphpublic boolean checkCombinatorics()