title: print each level in BFS
body: <p>So, i can traverse the list, but i can't print out each level. Not sure how.</p>
  
  <p>I have something like this:</p>
  
  <pre><code>$list = {
    "A" =&gt; ["C","D","E"],
    "B" =&gt; ["C","F"],
    "C" =&gt; ["A","B","D","F","E"],
    "D" =&gt; ["A","C","E"],
    "E" =&gt; ["A","C","D"],
    "F" =&gt; ["B","C"]
   }
  
  
  def BFS2()
    queue = ["A"]
    visited = {"A"=&gt;true}
    print "A "
      while(!queue.empty?)
        node = queue.pop()
        $list[node].each do |child|
          if visited[child] != true then
             print "#{child} "
             queue.push(child)
             visited[child] = true
           end
        end
      end
  end
  </code></pre>
  
  <p>instead of print it like</p>
  
  <pre><code>A C D E B F
  </code></pre>
  
  <p>id like to print it as so</p>
  
  <pre><code>A
  C D E
  B F
  </code></pre>
  
  <p>I've tried a few different things, but i can't seem to get it. Any help would be appreciated thanks.</p>