All Packages Class Hierarchy This Package Previous Next Index
Class structure.GraphList
java.lang.Object

+structure.GraphList
 public abstract class GraphList
 extends Object
 implements Graph
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");
...
 See Also:
 GraphListDirected, GraphListUndirected, GraphMatrix

add(Object)
 Add a vertex to the graph.

addEdge(Object, Object, Object)
 Add an edge between two vertices within the graph.

clear()
 Remove all vertices (and thus, edges) of the graph.

contains(Object)
 Test for vertex membership.

containsEdge(Object, Object)
 Test for edge membership.

degree(Object)
 Determine out degree of vertex.

edgeCount()
 Determine the number of edges in graph.

edges()
 Construct an iterator over all edges.

elements()
 Construct vertex iterator.

get(Object)
 Get reference to actual label of vertex.

getEdge(Object, Object)
 Get reference to actual label of edge.

isDirected()
 Determine if graph is directed.

isEmpty()
 Determine if graph is empty.

isVisited(Object)
 Return visited flag of vertex.

isVisitedEdge(Edge)
 Return visited flag of edge.

neighbors(Object)
 Construct an adjacent vertex iterator.

remove(Object)
 Remove a vertex from the graph.

removeEdge(Object, Object)
 Remove possible edge between vertices labeled vLabel1 and vLabel2.

reset()
 Clear visited flags of edges and vertices.

size()
 Determine number of vertices within graph.

visit(Object)
 Test and set visited flag of vertex.

visitEdge(Edge)
 Test and set visited flag of edge.
add
public void add(Object label)
 Add a vertex to the graph.
 Precondition:
 label is a nonnull label for vertex
 Postcondition:
 a vertex with label is added to graph.
if vertex with label is already in graph, no action.
 Parameters:
 label  Label of the vertex; should be nonnull.
addEdge
public abstract void addEdge(Object v1,
Object v2,
Object label)
 Add an edge between two vertices within the graph. Edge is directed
iff graph is directed. Duplicate edges are silently replaced.
Labels on edges may be null.
 Precondition:
 vtx1 and vtx2 are labels of existing vertices
 Postcondition:
 an edge (possibly directed) is inserted between
vtx1 and vtx2.
 Parameters:
 vtx1  First (or source, if directed) vertex.
 vtx2  Second (or destination, if directed) vertex.
 label  Label associated with the edge.
remove
public abstract Object remove(Object label)
 Remove a vertex from the graph. Associated edges are also
removed. Nonvertices are silently ignored.
 Precondition:
 label is nonnull vertex label
 Postcondition:
 vertex with "equals" label is removed, if found
 Parameters:
 label  The label of the vertex within the graph.
 Returns:
 The label associated with the vertex.
removeEdge
public abstract Object removeEdge(Object vLabel1,
Object vLabel2)
 Remove possible edge between vertices labeled vLabel1 and vLabel2.
Directed edges consider vLabel1 to be the source.
 Precondition:
 vLabel1 and vLabel2 are labels of existing vertices
 Postcondition:
 edge is removed, its label is returned
 Parameters:
 vLabel1  First (or source, if directed) vertex.
 vLabel2  Second (or destination, if directed) vertex.
 Returns:
 The label associated with the edge removed.
get
public Object get(Object label)
 Get reference to actual label of vertex. Vertex labels are matched
using their equals method, which may or may not test for actual
equivalence. Result remains part of graph.
 Postcondition:
 returns actual label of indicated vertex
 Parameters:
 label  The label of the vertex sought.
 Returns:
 The actual label, or null if none is found.
getEdge
public Edge getEdge(Object label1,
Object label2)
 Get reference to actual label of edge. Edge is identified by
the labels on associated vertices. If edge is directed, the
label1 indicates source.
 Postcondition:
 returns actual label of edge between vertices.
 Parameters:
 label1  The first (or source, if directed) vertex.
 label2  The second (or destination, if directed) vertex.
 Returns:
 The label associated with the edge, if found, or null.
contains
public boolean contains(Object label)
 Test for vertex membership.
 Postcondition:
 returns true iff vertex with "equals" label exists.
 Parameters:
 label  The label of the vertex sought.
 Returns:
 True iff vertex with matching label is found.
containsEdge
public boolean containsEdge(Object vLabel1,
Object vLabel2)
 Test for edge membership. If edges are directed, vLabel1
indicates source.
 Postcondition:
 returns true iff edge with "equals" label exists
 Parameters:
 vLabel1  First (or source, if directed) vertex.
 vLabel2  Second (or destination, if directed) vertex.
 Returns:
 True iff the edge exists within the graph.
visit
public boolean visit(Object label)
 Test and set visited flag of vertex.
 Postcondition:
 sets visited flag on vertex, returns previous value
 Parameters:
 label  Label of vertex to be visited.
 Returns:
 Previous value of visited flag on vertex.
visitEdge
public boolean visitEdge(Edge e)
 Test and set visited flag of edge.
 Precondition:
 sets visited flag on edge; returns previous value
 Parameters:
 e  Edge object that is part of graph.
 Returns:
 Previous value of the Edge's visited flag.
isVisited
public boolean isVisited(Object label)
 Return visited flag of vertex.
 Postcondition:
 returns visited flag on labeled vertex
 Parameters:
 label  Label of vertex.
 Returns:
 True if vertex has been visited.
isVisitedEdge
public boolean isVisitedEdge(Edge e)
 Return visited flag of edge.
 Postcondition:
 returns visited flag on edge between vertices
 Parameters:
 e  Edge of graph to be considered.
 Returns:
 True if the edge has been visited.
reset
public void reset()
 Clear visited flags of edges and vertices.
 Postcondition:
 resets visited flags to false
size
public int size()
 Determine number of vertices within graph.
 Postcondition:
 returns the number of vertices in graph
 Returns:
 The number of vertices within graph.
degree
public int degree(Object label)
 Determine out degree of vertex.
 Precondition:
 label labels an existing vertex
 Postcondition:
 returns the number of vertices adjacent to vertex
 Parameters:
 label  Label associated with vertex.
 Returns:
 The number of edges with this vertex as source.
edgeCount
public abstract int edgeCount()
 Determine the number of edges in graph.
 Postcondition:
 returns the number of edges in graph
 Returns:
 Number of edges in graph.
elements
public Iterator elements()
 Construct vertex iterator. Vertices are not visited in
any guaranteed order.
 Postcondition:
 returns iterator across all vertices of graph
 Returns:
 Iterator traversing vertices in graph.
neighbors
public Iterator neighbors(Object label)
 Construct an adjacent vertex iterator. Adjacent vertices
(those on destination of edge, if directed) are considered,
but not in any guaranteed order.
 Precondition:
 label is label of vertex in graph
 Postcondition:
 returns iterator over vertices adj. to vertex
each edge beginning at label visited exactly once
 Parameters:
 label  Label of the vertex.
 Returns:
 Iterator traversing the adjacent vertices of labeled vertex.
edges
public Iterator edges()
 Construct an iterator over all edges. Every directed/undirected
edge is considered exactly once. Order is not guaranteed.
 Postcondition:
 returns iterator across edges of graph
iterator returns edges; each edge visited once
 Returns:
 Iterator over edges.
clear
public void clear()
 Remove all vertices (and thus, edges) of the graph.
 Postcondition:
 removes all vertices from graph
isEmpty
public boolean isEmpty()
 Determine if graph is empty.
 Postcondition:
 returns true if graph contains no vertices
 Returns:
 True iff there are no vertices in graph.
isDirected
public boolean isDirected()
 Determine if graph is directed.
 Postcondition:
 returns true if edges of graph are directed
 Returns:
 True iff the graph is directed.
All Packages Class Hierarchy This Package Previous Next Index