Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public class GraphOperations {
  2.  
  3. public static int hopDistance(Graph graph, Vertex source, Vertex target){
  4.  
  5. Set<Vertex> searchTree = new HashSet<Vertex>();
  6. searchTree.add(source);
  7. int count = 0;
  8.  
  9. while (true){
  10.  
  11. for (Vertex v : searchTree){
  12.  
  13. if (v.equals(target)){
  14. return count;
  15. }
  16. else if (v.equals(searchTree[-1])){
  17. searchTree.addAll(getNeighbours(graph, v));
  18. count++;
  19. }
  20.  
  21. }
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement