edu.stanford.math.plex4.graph
public class UndirectedListGraph extends java.lang.Object implements AbstractUndirectedGraph
0 -- 1
| |
2 -- 3 -- 4
The following storage scheme is used: 1: {0} 2: {0} 3: {1, 2} 4: {3}Constructor and Description |
---|
UndirectedListGraph(AbstractUndirectedGraph graph)
This constructor initializes the graph with the contents of another
graph.
|
UndirectedListGraph(int numVertices)
Constructor which initializes the graph to consist of disconnected
vertices.
|
UndirectedListGraph(int[][] adjacencyMatrix)
Constructor which initializes the graph to contain the edges given in the
specified adjacency matrix.
|
UndirectedListGraph(int numVertices,
gnu.trove.TIntObjectHashMap<gnu.trove.TIntHashSet> adjacencySets) |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(int i,
int j)
This function adds the edge (i, j) to the graph.
|
boolean |
containsEdge(int i,
int j)
This function returns true if the edge (i, j) is in the graph,
and false otherwise.
|
int |
getDegree(int v) |
int[] |
getDegreeSequence() |
gnu.trove.TIntHashSet |
getLowerNeighbors(int i)
This function returns the set of neighbors of vertex i in the graph which
have indices less than i.
|
int[] |
getNeighbors(int v) |
int |
getNumEdges()
Gets the number of edges in the graph.
|
int |
getNumVertices()
Gets the number of vertices in the graph.
|
java.util.Iterator<edu.stanford.math.primitivelib.autogen.pair.IntIntPair> |
iterator()
This function returns an edge iterator that allows the user to
iterate over the set of edges in the graph.
|
void |
removeEdge(int i,
int j)
This function removes the edge (i, j) from the graph.
|
public UndirectedListGraph(int numVertices)
numVertices
- the number of vertices to initialize the graph withpublic UndirectedListGraph(int numVertices, gnu.trove.TIntObjectHashMap<gnu.trove.TIntHashSet> adjacencySets)
public UndirectedListGraph(AbstractUndirectedGraph graph)
graph
- the graph to initialize withpublic UndirectedListGraph(int[][] adjacencyMatrix)
adjacencyMatrix
- the adjacency matrix to initialize withpublic void addEdge(int i, int j)
AbstractUndirectedGraph
addEdge
in interface AbstractUndirectedGraph
i
- the first vertex of the edge to addj
- the second vertex of the edge to addpublic boolean containsEdge(int i, int j)
AbstractUndirectedGraph
containsEdge
in interface AbstractUndirectedGraph
i
- the first vertex of the edgej
- the second vertex of the edgepublic int getNumEdges()
AbstractUndirectedGraph
getNumEdges
in interface AbstractUndirectedGraph
public int getNumVertices()
AbstractUndirectedGraph
getNumVertices
in interface AbstractUndirectedGraph
public void removeEdge(int i, int j)
AbstractUndirectedGraph
removeEdge
in interface AbstractUndirectedGraph
i
- the first vertex of the edge to addj
- the second vertex of the edge to addpublic gnu.trove.TIntHashSet getLowerNeighbors(int i)
getLowerNeighbors
in interface AbstractUndirectedGraph
i
- the vertex to querypublic java.util.Iterator<edu.stanford.math.primitivelib.autogen.pair.IntIntPair> iterator()
AbstractUndirectedGraph
iterator
in interface AbstractUndirectedGraph
iterator
in interface java.lang.Iterable<edu.stanford.math.primitivelib.autogen.pair.IntIntPair>
public int getDegree(int v)
getDegree
in interface AbstractUndirectedGraph
public int[] getDegreeSequence()
getDegreeSequence
in interface AbstractUndirectedGraph
public int[] getNeighbors(int v)
getNeighbors
in interface AbstractUndirectedGraph