|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractStructure | +--structure.GraphList
Implementation of graph using adjacency lists. Edges are stored in lists off of vertex structure. Class is abstract: you must use GraphListDirected or GraphListUndirected to construct particular instances of graphs. Typical usage:
Graph g = new GraphListDirected(); g.add("harry"); g.add("sally"); g.addEdge("harry","sally","friendly"); ...
GraphListDirected
,
GraphListUndirected
,
GraphMatrix
Field Summary | |
protected Map |
dict
Map associating vertex labels with vertex structures. |
protected boolean |
directed
Whether or not graph is directed. |
Constructor Summary | |
protected |
GraphList(boolean dir)
Constructor of directed/undirected GraphList. |
Method Summary | |
void |
add(Object label)
Add a vertex to the graph. |
abstract void |
addEdge(Object v1,
Object v2,
Object label)
Add an edge between two vertices within the graph. |
void |
clear()
Remove all vertices (and thus, edges) of the graph. |
boolean |
contains(Object label)
Test for vertex membership. |
boolean |
containsEdge(Object vLabel1,
Object vLabel2)
Test for edge membership. |
int |
degree(Object label)
Determine out degree of vertex. |
abstract int |
edgeCount()
Determine the number of edges in graph. |
Iterator |
edges()
Construct an iterator over all edges. |
Object |
get(Object label)
Get reference to actual label of vertex. |
Edge |
getEdge(Object label1,
Object label2)
Get reference to actual edge. |
boolean |
isDirected()
Determine if graph is directed. |
boolean |
isEmpty()
Determine if graph is empty. |
boolean |
isVisited(Object label)
Return visited flag of vertex. |
boolean |
isVisitedEdge(Edge e)
Return visited flag of edge. |
Iterator |
iterator()
Construct vertex iterator. |
static void |
main(String[] argv)
|
Iterator |
neighbors(Object label)
Construct an adjacent vertex iterator. |
abstract Object |
remove(Object label)
Remove a vertex from the graph. |
abstract Object |
removeEdge(Object vLabel1,
Object vLabel2)
Remove possible edge between vertices labeled vLabel1 and vLabel2. |
void |
reset()
Clear visited flags of edges and vertices. |
int |
size()
Determine number of vertices within graph. |
boolean |
visit(Object label)
Test and set visited flag of vertex. |
boolean |
visitEdge(Edge e)
Test and set visited flag of edge. |
Methods inherited from class structure.AbstractStructure |
elements, hashCode, values |
Methods inherited from class java.lang.Object |
|
Methods inherited from interface structure.Structure |
elements, values |
Field Detail |
protected Map dict
protected boolean directed
Constructor Detail |
protected GraphList(boolean dir)
dir
- True if graph is to be directed.Method Detail |
public void add(Object label)
add
in interface Graph
label
- Label of the vertex; should be non-null.public abstract void addEdge(Object v1, Object v2, Object label)
addEdge
in interface Graph
vtx1
- First (or source, if directed) vertex.vtx2
- Second (or destination, if directed) vertex.label
- Label associated with the edge.public abstract Object remove(Object label)
remove
in interface Graph
label
- The label of the vertex within the graph.public abstract Object removeEdge(Object vLabel1, Object vLabel2)
removeEdge
in interface Graph
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.public Object get(Object label)
get
in interface Graph
label
- The label of the vertex sought.public Edge getEdge(Object label1, Object label2)
getEdge
in interface Graph
label1
- The first (or source, if directed) vertex.label2
- The second (or destination, if directed) vertex.public boolean contains(Object label)
contains
in interface Graph
contains
in class AbstractStructure
label
- The label of the vertex sought.public boolean containsEdge(Object vLabel1, Object vLabel2)
containsEdge
in interface Graph
vLabel1
- First (or source, if directed) vertex.vLabel2
- Second (or destination, if directed) vertex.public boolean visit(Object label)
visit
in interface Graph
label
- Label of vertex to be visited.public boolean visitEdge(Edge e)
visitEdge
in interface Graph
e
- Edge object that is part of graph.public boolean isVisited(Object label)
isVisited
in interface Graph
label
- Label of vertex.public boolean isVisitedEdge(Edge e)
isVisitedEdge
in interface Graph
e
- Edge of graph to be considered.public void reset()
reset
in interface Graph
public int size()
size
in interface Graph
public int degree(Object label)
degree
in interface Graph
label
- Label associated with vertex.public abstract int edgeCount()
edgeCount
in interface Graph
public Iterator iterator()
iterator
in interface Graph
public Iterator neighbors(Object label)
neighbors
in interface Graph
label
- Label of the vertex.public Iterator edges()
edges
in interface Graph
public void clear()
clear
in interface Graph
public boolean isEmpty()
isEmpty
in interface Graph
isEmpty
in class AbstractStructure
public boolean isDirected()
isDirected
in interface Graph
public static void main(String[] argv)
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |