Guest User

Untitled

a guest
Jan 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. /**
  2. * This method prints the path from FROM to TO.
  3. */
  4. private void path(int[] visited, int to){
  5. //LinkedList is used to print the vertices in the order FROM to To.
  6. LinkedList<Integer> path = new LinkedList<Integer>();
  7. int first = to;
  8. while(visited[to] != to){
  9. path.addFirst(to);
  10. to = visited[to];
  11. }
  12. path.add(first);
  13. for (int i = 0; i < path.size(); i++) {
  14. System.out.print(path.get(i));
  15. }
  16. }
Add Comment
Please, Sign In to add comment