Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Queue<T> q = new LinkedList<>();
- HashMap<T, boolean> visited = new HashMap<>();
- q.add(vertLabel1);
- while (!q.isEmpty()) {
- T current = q.remove(); // remove the head of queue
- for(T neigh : neighbours(current)){//add current nodes neighbours to the queue
- if(neigh != null && !visited.get(current)){
- q.add(neigh);
- visited.put(neigh, true);
- if(current == vertLabel2){
- return q.size();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement