public class GraphImplementation extends GraphAbstract
GraphAbstract.GraphEdge, GraphAbstract.GraphNodecities, mileages| Constructor | Description |
|---|---|
GraphImplementation() |
| Modifier and Type | Method | Description |
|---|---|---|
void |
breadthFirst(java.lang.String startCity) |
|
void |
depthFirst(int index,
java.util.ArrayList<java.lang.Integer> visited) |
|
void |
depthFirst(java.lang.String startCity) |
|
static void |
main(java.lang.String[] args) |
|
(package private) static java.util.ArrayList<java.lang.String> |
readFile(java.lang.String filename) |
Reads the contents of file to
ArrayList |
void |
readGraph(java.lang.String filename) |
Reads mileage chart from CSV file and builds lists of nodes (cities) and edges (distances).
|
void |
shortestPath(java.lang.String fromCity,
java.lang.String toCity) |
|
(package private) static void |
writeFile(java.lang.String filename,
java.util.ArrayList<java.lang.String> contents) |
Write contents of
ArrayList to file |
void |
writeGraph(java.lang.String filename) |
Writes mileage graph to DOT file.
|
public static void main(java.lang.String[] args)
public void readGraph(java.lang.String filename)
GraphAbstract
The first line contains all the cities which should be represented as GraphAbstract.GraphNodes
The successive lines start with a city, followed by a list of mileages to other cities.
To avoid redundancy, not all the values are filled in, ignore empty entries.
When you read a mileage, for example from Fort Collins to Denver, create only one
entry in the mileages array, but add the edge to both cities.
First extract all the edges, then sort the edges by mileage, then add the edges associated with each node.
readGraph in class GraphAbstractfilename - the CSV filepublic void writeGraph(java.lang.String filename)
GraphAbstract
Traverses the data structures created above and writes nodes and edges in GraphViz format.
You will build the GraphViz format into an ArrayList, which will then be written to file
using the writeFile(String, ArrayList) method.
Use the provided example and the following directions to implement this method:
\u2264100 miles, blue for \u2264200 miles,
magenta for \u2264300 miles, and red otherwise.
HINT: Match the file format exactly as provided in order to pass automated grading!
writeGraph in class GraphAbstractfilename - the output file namepublic void depthFirst(java.lang.String startCity)
depthFirst in class GraphAbstractpublic void depthFirst(int index,
java.util.ArrayList<java.lang.Integer> visited)
public void breadthFirst(java.lang.String startCity)
breadthFirst in class GraphAbstractpublic void shortestPath(java.lang.String fromCity,
java.lang.String toCity)
shortestPath in class GraphAbstractstatic java.util.ArrayList<java.lang.String> readFile(java.lang.String filename)
ArrayListfilename - the file to read fromstatic void writeFile(java.lang.String filename,
java.util.ArrayList<java.lang.String> contents)
ArrayList to filefilename - the name of the file to write tocontents - an ArrayList of contents to write