public class CarlUnweightedGraph extends java.lang.Object implements UnweightedGraph
| Constructor and Description |
|---|
CarlUnweightedGraph()
Default constructor: an empty directed graph.
|
CarlUnweightedGraph(boolean directed)
Constructs an empty graph with the specified directedness.
|
CarlUnweightedGraph(boolean directed,
int n)
Constructs a graph with N vertices and the specified directedness.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdge(int begin,
int end)
Adds an edge between two vertices.
|
int |
addVertex()
Adds a new vertex.
|
void |
clear()
Removes all vertices and edges from the graph.
|
int |
getDegree(int v)
Returns the out-degree of the specified vertex.
|
int |
getInDegree(int v)
Returns the in-degree of the specified vertex.
|
java.lang.Iterable<java.lang.Integer> |
getNeighbors(int v)
Returns an iterator over the neighbors of the specified vertex.
|
boolean |
hasEdge(int begin,
int end)
Checks whether an edge exists between two vertices.
|
boolean |
isDirected()
Returns true if the graph is directed.
|
boolean |
isEmpty()
Returns true if there are no vertices in the graph.
|
int |
numEdges()
Returns the number of edges in the graph.
|
int |
numVerts()
Returns the number of vertices in the graph.
|
public CarlUnweightedGraph()
public CarlUnweightedGraph(boolean directed)
public CarlUnweightedGraph(boolean directed,
int n)
public int addVertex()
public boolean addEdge(int begin,
int end)
addEdge in interface UnweightedGraphpublic boolean hasEdge(int begin,
int end)
public int getDegree(int v)
public int getInDegree(int v)
getInDegree in interface Graphpublic java.lang.Iterable<java.lang.Integer> getNeighbors(int v)
getNeighbors in interface Graphpublic int numVerts()
public int numEdges()
public boolean isDirected()
isDirected in interface Graphpublic boolean isEmpty()