Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1.         Queue<T> q = new LinkedList<>();
  2.         HashMap<T, boolean> visited = new HashMap<>();
  3.  
  4.         q.add(vertLabel1);
  5.         while (!q.isEmpty()) {
  6.             T current = q.remove();  // remove the head of queue
  7.             for(T neigh : neighbours(current)){//add current nodes neighbours to the queue
  8.                 if(neigh != null && !visited.get(current)){
  9.                     q.add(neigh);
  10.                     visited.put(neigh, true);
  11.                     if(current == vertLabel2){
  12.                         return q.size();
  13.                     }
  14.                 }
  15.             }
  16.  
  17.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement