|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMysteryUnweightedGraphImplementation
public class MysteryUnweightedGraphImplementation
An implementation of the Unweighted Graph ADT. 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 Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MysteryUnweightedGraphImplementation()
public MysteryUnweightedGraphImplementation(boolean directed)
public MysteryUnweightedGraphImplementation(boolean directed, int N)
Method Detail |
---|
public int addVertex()
addVertex
in interface Graph
public boolean addEdge(int begin, int end)
addEdge
in interface UnweightedGraph
public boolean hasEdge(int begin, int end)
hasEdge
in interface Graph
public int getDegree(int v)
getDegree
in interface Graph
public int getInDegree(int v)
getInDegree
in interface Graph
public java.lang.Iterable<java.lang.Integer> getNeighbors(int v)
getNeighbors
in interface Graph
public int numVerts()
numVerts
in interface Graph
public int numEdges()
numEdges
in interface Graph
public boolean isDirected()
isDirected
in interface Graph
public boolean isEmpty()
isEmpty
in interface Graph
public void clear()
clear
in interface Graph
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |