|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectkth.csc.inda.MatrixGraph
public class MatrixGraph
A graph with a fixed number of vertices implemented using an adjacency matrix. Space complexity is Θ(n2), where n is the number of vertices.
| Field Summary |
|---|
| Fields inherited from interface kth.csc.inda.Graph |
|---|
NO_COST |
| Constructor Summary | |
|---|---|
MatrixGraph(int n)
Constructs a MatrixGraph with n vertices and no edges. |
|
| Method Summary | |
|---|---|
void |
add(int from,
int to)
Inserts a directed edge. |
void |
add(int from,
int to,
int c)
Inserts an edge with edge cost c. |
void |
addBi(int v,
int w)
Inserts two edges between v and w. |
void |
addBi(int v,
int w,
int c)
Inserts edges with edge cost c between v and w. |
int |
cost(int v,
int w)
Returns the edge cost if v and w are adjacent and an edge cost has been assigned, NO_COST otherwise. |
int |
degree(int v)
Returns the degree of vertex v. |
boolean |
hasEdge(int v,
int w)
Returns true if there is an edge from v to w. |
VertexIterator |
neighbors(int v)
Returns an iterator of vertices adjacent to v. |
int |
numEdges()
Returns the number of edges in this graph. |
int |
numVertices()
Returns the number of vertices in this graph. |
void |
remove(int from,
int to)
Removes the edge. |
void |
removeBi(int v,
int w)
Removes the edges between v and w. |
java.lang.String |
toString()
Returns a string representation of this graph. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MatrixGraph(int n)
java.lang.IllegalArgumentException - if n < 0| Method Detail |
|---|
public int numVertices()
numVertices in interface Graphpublic int numEdges()
numEdges in interface Graph
public int degree(int v)
throws java.lang.IllegalArgumentException
degree in interface Graphv - vertex
java.lang.IllegalArgumentException - if v is out of range
public VertexIterator neighbors(int v)
throws java.lang.IllegalArgumentException
neighbors in interface Graphv - vertex
java.lang.IllegalArgumentException - if v is out of range
public boolean hasEdge(int v,
int w)
throws java.lang.IllegalArgumentException
hasEdge in interface Graphv - vertexw - vertex
java.lang.IllegalArgumentException - if v or w are out of range
public int cost(int v,
int w)
throws java.lang.IllegalArgumentException
cost in interface Graphv - vertexw - vertex
java.lang.IllegalArgumentException - if v or w are out of range
public void add(int from,
int to)
throws java.lang.IllegalArgumentException
add in interface Graphfrom - vertexto - vertex
java.lang.IllegalArgumentException - if from or to are out of range
public void add(int from,
int to,
int c)
throws java.lang.IllegalArgumentException
add in interface Graphfrom - vertexto - vertexc - edge cost, c >= 0
java.lang.IllegalArgumentException - if from or to are out of range
public void addBi(int v,
int w)
throws java.lang.IllegalArgumentException
addBi in interface Graphv - vertexw - vertex
java.lang.IllegalArgumentException - if v or w are out of range
public void addBi(int v,
int w,
int c)
throws java.lang.IllegalArgumentException
addBi in interface Graphv - vertexw - vertexc - edge cost, c >= 0
java.lang.IllegalArgumentException - if v or w are out of range
public void remove(int from,
int to)
throws java.lang.IllegalArgumentException
remove in interface Graphfrom - vertexto - vertex
java.lang.IllegalArgumentException - if from or to are out of range
public void removeBi(int v,
int w)
throws java.lang.IllegalArgumentException
removeBi in interface Graphv - vertexw - vertex
java.lang.IllegalArgumentException - if v or w are out of rangepublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||