public class Edge { public Vertex vertex1, vertex2; // undirected edge -- no significance public double weight; // the distance btwn the two vertices -- used // as the cost for shortest-path / MST problems public Edge(Vertex v1, Vertex v2, double wt) { vertex1 = v1; vertex2 = v2; weight = wt; } // returns the other vertex that's a member of the edge. If v is // not in the edge, throw an IllegalArgumentException. Vertex opposite(Vertex v) { if (v.equals(vertex1)) { return vertex2; } else if (v.equals(vertex2)) { return vertex1; } else { throw new IllegalArgumentException(); } } public String toString() { return(vertex1.toString() + "<->" + vertex2.toString()); } }