Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This method prints the path from FROM to TO.
- */
- private void path(int[] visited, int to){
- //LinkedList is used to print the vertices in the order FROM to To.
- LinkedList<Integer> path = new LinkedList<Integer>();
- int first = to;
- while(visited[to] != to){
- path.addFirst(to);
- to = visited[to];
- }
- path.add(first);
- for (int i = 0; i < path.size(); i++) {
- System.out.print(path.get(i));
- }
- }
Add Comment
Please, Sign In to add comment