title: Shortest path (fewest nodes) for unweighted graph
body: <p>I'm trying build a method which returns the shortest path from one node to another in an unweighted graph.  I considered the use of Dijkstra's but this seems a bit overkill since I only want one pair.  Instead I have implemented a breadth-first search, but the trouble is that my returning list contains some of the nodes that I don't want - how can I modify my code to achieve my goal?</p>
  
  <pre><code>public List&lt;Node&gt; getDirections(Node start, Node finish){
      List&lt;Node&gt; directions = new LinkedList&lt;Node&gt;();
      Queue&lt;Node&gt; q = new LinkedList&lt;Node&gt;();
      Node current = start;
      q.add(current);
      while(!q.isEmpty()){
          current = q.remove();
          directions.add(current);
          if (current.equals(finish)){
              break;
          }else{
              for(Node node : current.getOutNodes()){
                  if(!q.contains(node)){
                      q.add(node);
                  }
              }
          }
      }
      if (!current.equals(finish)){
          System.out.println("can't reach destination");
      }
      return directions;
  }
  </code></pre>