title: Shortest path using HashMaps and ArrayList (using BFS)
body: <p>I'm trying to find the shortest path of finding friends. If person X wants to connect to person Y, I want to print out the shortest path of friends in order for X to get to Y. Everytime I run the code, I get null as a result.</p>
  
  <p>public void shortest(String first, String target){</p>
  
  <pre><code>    HashMap&lt;String, String&gt; prev = new HashMap&lt;String, String&gt;();
      Queue&lt;PersonNode&gt; q = new LinkedList&lt;PersonNode&gt;();
      PersonNode firstPerson = hash.get(first);
  
      firstPerson.visited = true;
      prev.put(first, first + " ");
      q.add(firstPerson);
  
      while(!q.isEmpty()){    
          PersonNode curr = q.remove();
  
          if(!curr.visited){
              curr.visited = true;
              if(curr.equals(target)){
                  break;
              }
              else{
                  for(int i =0; i &lt; curr.list.size(); i++){
                      if(curr.list.get(i).visited = false){
                          q.add(curr.list.get(i));
                          curr.list.get(i).visited = true;
                          prev.put(curr.list.get(i).name, prev.get(curr.list.get(i).name) + curr.list.get(i));
  
                      }
                  }
  
              }
              if(!curr.equals(target)){
                  System.out.println("They have no connections");
              }
  
          }
      }
      System.out.println(prev.get(target));
  }
  </code></pre>