Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map<V,Integer> m = new HashMap();
- Queue <V> q = new LinkedList();
- int stamp = 0;
- for(V i : g.vertices()){
- if(i.equals(src)){
- m.put(i,stamp);
- }else{
- m.put(i,-1);
- }
- }
- q.add(src);
- while(!q.isEmpty()){
- V temp = q.remove();
- stamp++;
- for(V w : g.adjacentFrom(temp)){
- if(m.get(w) == -1){
- q.add(w);
- m.put(w,stamp);
- }else if(w.equals(dst)){
- stamp++;
- m.put(w, stamp);
- break;
- }
- }
- }
- return stamp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement