Color.java package graph; public enum Color { //for coloring nodes BLACK, WHITE, GREY; } Edge.java package
Fantastic news! We've Found the answer you've been seeking!
Question:
Color.java
package graph; public enum Color { //for coloring nodes BLACK, WHITE, GREY; }
Edge.java
package graph; public class Edge { Vertex from, to; int weight; public Edge(Vertex from, Vertex to, int weight) { this.from = from; this.to = to; this.weight = weight; } public Edge(Vertex from, Vertex to) { this.from = from; this.to = to; this.weight = 1; } public String toString() { return "(" + from + "->" + to + ", " + weight + ")"; } // auto-generated: hashes on all fields public int hashCode() { return weight+from.hashCode()+to.hashCode(); } // auto-generated: compares all fields public boolean equals(Object o) { Edge e = (Edge)o; return from.equals(e.from)&&to.equals(e.to)&& weight==e.weight; } }
Graph.java
package graph; import java.util.*; public interface Graph { Collection getVertices(); ArrayList depthFirstSearch(); ArrayList topologicalSortDFS(); ArrayList topologicalSortQueue(); ArrayList shortestPath(int source, int target); }
Vertex.java
package graph; public class Vertex implements Comparable{ int value; int discoveryTime; //for DFS and Shortest Path int finishTime; //for DFS Color color; Vertex p; //can be used for DFS Tree and Shortest Path int inDegree; //for topological sort Vertex(int val) { value = val; } public String toString() { return Integer.toString(value); } /****** NOTE THAT WE REALLY ONLY CARE ABOUT VALUES ***********/ //This is not a great hashCode public int hashCode() { return value; } //Compare vertices public boolean equals(Object o) { Vertex v = (Vertex)o; return v.value==value; } public int compareTo(Vertex v) { return value - v.value; } }
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date: