title: Directed graph in java
body: <p>Can anyone help me implement the bfs on my graph?  I put my graph implementation here and the bfs algorithm to my graph . I just need some ideas how to do it.</p>
  
  <pre><code>public class DiGraph&lt;V&gt; {
  
          public static class Edge&lt;V&gt;{
              private V vertex;
              private int cost;
  
              public Edge(V v, int c){
                  vertex = v; 
                  cost = c;
              }
              @Override
              public String toString() {
                  return "{" + vertex + ", " + cost + "}";
              }
          }
  
          private Map&lt;V, List&lt;Edge&lt;V&gt;&gt;&gt; inNeighbors = new HashMap&lt;V, List&lt;Edge&lt;V&gt;&gt;&gt;();
          private Map&lt;V, List&lt;Edge&lt;V&gt;&gt;&gt; outNeighbors = new HashMap&lt;V, List&lt;Edge&lt;V&gt;&gt;&gt;();
          public int nr_vertices;
          public int nr_edges;
  
          public String toString () {
              StringBuffer s = new StringBuffer();
              for (V v: inNeighbors.keySet()) 
                  s.append("\n    " + v + " -&gt; " + inNeighbors.get(v));
              return s.toString();                
          }
  
          public void addIn (V vertex) {
              if (inNeighbors.containsKey(vertex)) 
                  return;
  
              inNeighbors.put(vertex, new ArrayList&lt;Edge&lt;V&gt;&gt;());
  
          }
  
          public void addOut(V vertex) {
              if (outNeighbors.containsKey(vertex)) 
                  return;
              outNeighbors.put(vertex, new ArrayList&lt;Edge&lt;V&gt;&gt;());
          }
  
          public boolean contains (V vertex) {
              return inNeighbors.containsKey(vertex);
          }
  
          public void add (V from, V to, int cost) {
              this.addIn(from); 
              this.addIn(to);
              this.addOut(to);
              this.addOut(from);
              inNeighbors.get(from).add(new Edge&lt;V&gt;(to,cost));
              outNeighbors.get(to).add(new Edge&lt;V&gt;(from,cost));
          }
  
          public int outDegree (V vertex) {
              return inNeighbors.get(vertex).size();
          }
  
          public int inDegree (V vertex) {
              return inboundNeighbors(vertex).size();
          }
      }
  
      public void bfs()
      {
          // BFS uses Queue data structure
          Queue queue = new LinkedList();
          queue.add(this.rootNode);
          printNode(this.rootNode);
          rootNode.visited = true;
          while(!queue.isEmpty()) {
              Node node = (Node)queue.remove();
              Node child=null;
              while((child=getUnvisitedChildNode(node))!=null) {
                  child.visited=true;
                  printNode(child);
                  queue.add(child);
              }
          }
          // Clear visited property of nodes
          clearNodes();
      }
  </code></pre>
  
  <p>The bfs algorithm i took it from the internet, I understand it but it's for general cases, I don't know how to adapt it to my graph</p>