Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. 1-2
  2. 1-4
  3. 2-3
  4. 3-6
  5. 4-5
  6. 5-6
  7.  
  8. private static void bfs() {
  9. boolean[] visited = new boolean[virsotnes.length];
  10. Queue<Integer> queue = new LinkedList<>();
  11. String[] pathTo = new String[virsotnes.length];
  12. for (int v=1; v < visited.length; v++) {
  13. if (!visited[v]) {
  14. pathTo[v] = v+"";
  15. System.out.println("nSTARTING AT " + virsotnes[v].virs);
  16. queue.clear();
  17. bfs(v, visited, queue,pathTo);
  18. }
  19. }
  20.  
  21. }
  22.  
  23. private static void bfs(int start, boolean[] visited,Queue<Integer>queue,String []pathTo) {
  24. visited[start] = true;
  25. System.out.println("visiting " + virsotnes[start].virs);
  26. queue.add(start);
  27.  
  28. while (!queue.isEmpty()) {
  29. int v = queue.remove();
  30. //System.out.print(v+"this is v");
  31. for (Neighbor nbr=virsotnes[v].virsotne; nbr != null; nbr=nbr.next) {
  32.  
  33. int vnum = nbr.vertexNum;
  34. if (!visited[vnum]) {
  35. System.out.println("n" + virsotnes[v].virs + "--" + virsotnes[vnum].virs);
  36. visited[vnum] = true;
  37. queue.add(vnum);
  38. pathTo[vnum] = pathTo[v] + vnum;
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement