

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object structure5.AbstractStructure<V> structure5.GraphList<V,E> structure5.GraphListDirected<V,E>
public class GraphListDirected<V,E>
A GraphListDirected is a listbased graph representation that consists of a collection of vertices and directed edges. Portions of the graph may be marked visited to support iterative algorithms. Iteration is provided over vertices, edges, and vertices adjacent to a particular vertex.
Example Usage:
To create a graph representation of the movie theaters nearest the Williams College Department of Computer Science's unix laboratory, and to print these theaters out in order of increasing distance, we could use the following:
public static void main(String[] argv){ Graph theaters = newGraphListDirected()
; FibHeap heap = new FibHeap(); //instantiate array of locations String[] locations = new String[]{"TCL 312", "Images Cinema", "Movie Plex 3", "Cinema 1,2,&3", "Cinema 7", "Berkshire Mall Cinemas" ,"Hathaway's Drive Inn Theatre", "Hollywood DriveIn Theatre"}; //instantiate array of distances betweenlocation[0]
//and movie theaters double[] distances = new double[]{1, 0.0, 12.6, 12.9, 12.9, 14.7, 16.5, 18.0}; //build graph for(int i=0; i < locations.length; i++) theaters.add(locations[i]); for(int i=1; i < distances.length; i++){ theaters.addEdge(locations[0],locations[i],new Double(distances[i]))
; } //place neighbors of lab in into priority queue for(Iterator i=theaters.neighbors(locations[0])
; i.hasNext();){ Object theater = i.next(); Object distance = theaters.getEdge(locations[0], theater).label()
; heap.add(new ComparableAssociation((Comparable)distance,theater)); } //print out theaters in order of distance while(!heap.isEmpty()){ ComparableAssociation show = (ComparableAssociation)heap.remove(); System.out.println(show.getValue()+" is "+show.getKey()+" miles away."); } }
GraphList
,
GraphListUndirected
,
GraphMatrixDirected
Constructor Summary  

GraphListDirected()
Construct a directed, adjacencylist based graph. 
Method Summary  

void 
addEdge(V vLabel1,
V vLabel2,
E label)
Add an edge between two vertices within the graph. 
int 
edgeCount()
Determine the number of edges in graph. 
V 
remove(V label)
Remove a vertex from the graph. 
E 
removeEdge(V vLabel1,
V vLabel2)
Remove possible edge between vertices labeled vLabel1 and vLabel2. 
String 
toString()
Construct a string representation of graph. 
Methods inherited from class structure5.GraphList 

add, clear, contains, containsEdge, degree, edges, get, getEdge, isDirected, isEmpty, isVisited, isVisitedEdge, iterator, main, neighbors, reset, size, visit, visitEdge 
Methods inherited from class structure5.AbstractStructure 

elements, hashCode, values 
Methods inherited from class java.lang.Object 

equals, getClass, notify, notifyAll, wait, wait, wait 
Methods inherited from interface structure5.Structure 

elements, values 
Constructor Detail 

public GraphListDirected()
Method Detail 

public void addEdge(V vLabel1, V vLabel2, E label)
addEdge
in interface Graph<V,E>
addEdge
in class GraphList<V,E>
vLabel1
 Source vertex.vLabel2
 Destination vertex.label
 Label associated with the edge.public V remove(V label)
remove
in interface Graph<V,E>
remove
in interface Structure<V>
remove
in class GraphList<V,E>
label
 The label of the vertex within the graph.
public E removeEdge(V vLabel1, V vLabel2)
removeEdge
in interface Graph<V,E>
removeEdge
in class GraphList<V,E>
vLabel1
 Source vertex.vLabel2
 Destination vertex.
public int edgeCount()
edgeCount
in interface Graph<V,E>
edgeCount
in class GraphList<V,E>
public String toString()
toString
in class Object


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 