|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Graph
A graph with a fixed number of vertices. The vertices are numbered from 0 to n-1, were n is the number of vertices in the graph. Edges may be added or removed from the graph. An edge may have an optional non-negative cost.
Field Summary | |
---|---|
static int |
NO_COST
An edge with no cost has this value. |
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. |
Field Detail |
---|
static final int NO_COST
Method Detail |
---|
int numVertices()
int numEdges()
int degree(int v) throws java.lang.IllegalArgumentException
v
- vertex
java.lang.IllegalArgumentException
- if v is out of rangeVertexIterator neighbors(int v) throws java.lang.IllegalArgumentException
v
- vertex
java.lang.IllegalArgumentException
- if v is out of rangeboolean hasEdge(int v, int w) throws java.lang.IllegalArgumentException
v
- vertexw
- vertex
java.lang.IllegalArgumentException
- if v or w are out of rangeint cost(int v, int w) throws java.lang.IllegalArgumentException
v
- vertexw
- vertex
java.lang.IllegalArgumentException
- if v or w are out of rangevoid add(int from, int to) throws java.lang.IllegalArgumentException
from
- vertexto
- vertex
java.lang.IllegalArgumentException
- if from or to are out of rangevoid add(int from, int to, int c) throws java.lang.IllegalArgumentException
c
- edge cost, c >= 0from
- vertexto
- vertex
java.lang.IllegalArgumentException
- if from or to are out of range
java.lang.IllegalArgumentException
- if c < 0void addBi(int v, int w) throws java.lang.IllegalArgumentException
v
- vertexw
- vertex
java.lang.IllegalArgumentException
- if v or w are out of rangevoid addBi(int v, int w, int c) throws java.lang.IllegalArgumentException
c
- edge cost, c >= 0v
- vertexw
- vertex
java.lang.IllegalArgumentException
- if v or w are out of range
java.lang.IllegalArgumentException
- if c < 0void remove(int from, int to) throws java.lang.IllegalArgumentException
from
- vertexto
- vertex
java.lang.IllegalArgumentException
- if from or to are out of rangevoid removeBi(int v, int w) throws java.lang.IllegalArgumentException
v
- vertexw
- vertex
java.lang.IllegalArgumentException
- if v or w are out of range
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |