Solution to Question 3 on the CS 10 W12 Final Exam This is a solution that uses the Graph interface from the sixth edition to the textbook. In W12 we used the fifth edition, which had a different Graph interface. /* * Sample solution to W12 final graph question * Finds the edges in a path given the vertices. * Precondition - verts is not an empty list. * @param verts a list containing the vertices in the path * @return the list of edges in the path * @throws IllegalStateException if not a valid path */ public List> getPath(List> verts) { List> returnList = new ArrayList>(); Iterator> iter = verts.iterator(); Vertex first = iter.next(); while(iter.hasNext()) { Vertex second = iter.next(); Edge e = this.getEdge(first, second); if(e != null) { returnList.add(e); first = second; } else throw new IllegalStateException("Not a valid path"); } return returnList; }