Graph
Class Graph

java.lang.Object
  |
  +--Graph.Graph

public class Graph
extends Object

Represents a graph...in this case, the connections between cities. Includes static methods to test the class. Could be generalized. Implement the connectedComponents() method to find the connected components of the graph. Warning: You may find this challenging! If you want more: Implement the findPath method that returns a path between 2 vertices.


Field Summary
private  Map adjacency
           
 
Constructor Summary
Graph()
           
 
Method Summary
private  void addAdjacency(Vertex v1, Vertex v2)
          Adds the edge.
 void addEdge(Vertex v1, Vertex v2)
          Adds a new edge.
 void addVertex(Vertex v)
          Adds a new vertex.
 List connectedComponents()
          You should implement the algorithm described in the notes
 Path findPath(Vertex v1, Vertex v2)
          Returns a path from v1 to v2.
private static Graph generateGraph(List vertices)
          Builds a sample Graph object.
static void main(String[] args)
          Tests the Graph class.
 String toString()
          Convert to a String.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

adjacency

private Map adjacency
Constructor Detail

Graph

public Graph()
Method Detail

addVertex

public void addVertex(Vertex v)
Adds a new vertex.

addEdge

public void addEdge(Vertex v1,
                    Vertex v2)
Adds a new edge.

addAdjacency

private void addAdjacency(Vertex v1,
                          Vertex v2)
Adds the edge.

connectedComponents

public List connectedComponents()
You should implement the algorithm described in the notes

findPath

public Path findPath(Vertex v1,
                     Vertex v2)
Returns a path from v1 to v2.

toString

public String toString()
Convert to a String. The Graph is represented as its ajavency list.
Overrides:
toString in class Object

main

public static void main(String[] args)
Tests the Graph class. Builds a graph, finds connected components, and a path.

generateGraph

private static Graph generateGraph(List vertices)
Builds a sample Graph object. Builds a graph, finds connected components, and a path.