Rewrite method dij kstrasAlgorithm to use a priority queue as we did for method pri msA 1 gori thm. When inserting edges into the priority queue, the weight is replaced by the total distance from the source vertex to the destination vertex. The source vertex, however, remains unchanged as it is the predecessor in the shortest path.
A third possi. e representation of a graph is to use the TreeSet class to contain the edges. By defining a comparator that compares first on the source vertex and then the destination vertex, we can use the subSet method to create a view that contains only edges origj[lating at a specified vertex and then use the iterator of that view to iterate through edges. Design and implement a class that meet the requirements of the Graph interface and uses a TreeSet to hold the edges.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here