public class MysteryUnweightedGraphImplementation extends java.lang.Object implements UnweightedGraph
This class can represent both directed and undirected graphs, but the choice must be made at construction time, and is final.
Technically, this implementation supports self-loops; it makes no effort to prevent these.
Any method that takes one or more vertex IDs as arguments may throw an IndexOutOfBoundsException if any input ID is out of bounds.
Constructor and Description |
---|
MysteryUnweightedGraphImplementation()
Default constructor: an empty directed graph.
|
MysteryUnweightedGraphImplementation(boolean directed)
Constructs an empty graph with the specified directedness.
|
MysteryUnweightedGraphImplementation(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 unweighted 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 iterable object that allows iteration over the neighbors of
the specified vertex.
|
boolean |
hasEdge(int begin,
int end)
Returns 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.
|
java.lang.String |
toString() |
public MysteryUnweightedGraphImplementation()
public MysteryUnweightedGraphImplementation(boolean directed)
public MysteryUnweightedGraphImplementation(boolean directed, int N)
public int addVertex()
Graph
public boolean addEdge(int begin, int end)
UnweightedGraph
addEdge
in interface UnweightedGraph
public boolean hasEdge(int begin, int end)
Graph
public int getDegree(int v)
Graph
public int getInDegree(int v)
Graph
getInDegree
in interface Graph
public java.lang.Iterable<java.lang.Integer> getNeighbors(int v)
Graph
getNeighbors
in interface Graph
public int numVerts()
Graph
public int numEdges()
Graph
public boolean isDirected()
Graph
isDirected
in interface Graph
public boolean isEmpty()
Graph
public void clear()
Graph
public java.lang.String toString()
toString
in class java.lang.Object