Class CourseGraph

java.lang.Object
  |
  +--CourseGraph

public class CourseGraph
extends java.lang.Object

Maintain the adjacency list (Map of GraphNode's )that represents the DAG


Constructor Summary
CourseGraph()
          Create a course graph with a java.util HashMap
 
Method Summary
 void addEdge(java.lang.String fromCourseID, java.lang.String toCourseID)
          Add an edge in the DAG- precondition: fromCourseID and toCourseID are both already vertices in the graph, placed there by addNode
 void addNode(Course c)
          Add a new course vertex to the graph
 boolean elementOf(java.lang.String courseID)
          Does this courseID represent a vertix in the graph ?
 GraphNode getNode(java.lang.String id)
          Get a GraphNode at this ID or return null if not present
 int getNumVertices()
          Return the size of the graph
static void main(java.lang.String[] arg)
          Test routine
 void topologicalSort()
          Displays all possible paths that meet all prerequistes and cover every course.
 java.lang.String toString()
          Convert the DAG to a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CourseGraph

public CourseGraph()
Create a course graph with a java.util HashMap
Method Detail

getNumVertices

public int getNumVertices()
Return the size of the graph

addNode

public void addNode(Course c)
Add a new course vertex to the graph

getNode

public GraphNode getNode(java.lang.String id)
Get a GraphNode at this ID or return null if not present

addEdge

public void addEdge(java.lang.String fromCourseID,
                    java.lang.String toCourseID)
Add an edge in the DAG- precondition: fromCourseID and toCourseID are both already vertices in the graph, placed there by addNode

elementOf

public boolean elementOf(java.lang.String courseID)
Does this courseID represent a vertix in the graph ?

toString

public java.lang.String toString()
Convert the DAG to a String
Overrides:
toString in class java.lang.Object

topologicalSort

public void topologicalSort()
Displays all possible paths that meet all prerequistes and cover every course. preconditions: The graph has no cycles. There exists at least one node with inDegree 0 or all nodes have inDegree of -1. Each prerequiste has a node in the graph and the edges beteen nodes have been constructed according to the prerequisties. postcondition: The graph is left unchanged.

main

public static void main(java.lang.String[] arg)
Test routine