code: public List<N> bfs(N root) {
          List<N> order = new ArrayList<>();
          Queue<N> queue = new ArrayDeque<>();
          queue.add(root);
  
          // Unmark all the nodes.
          this.setMarkedAllNodes(false);
      
          while (!queue.isEmpty()) {
              // Process the next node in the queue.
              N node = queue.remove();
              if (!node.isMarked()) {
                  // Add node only if not marked.
                  order.add(node);
                  node.setMarked(true);
              }
              
              // For each neighbor...
              for (E edge : node.getOutEdges()) {
                  N neighbor = edge.getChild();
                  if (!neighbor.isMarked()) {
                      // Queue if not marked.
                      queue.add(neighbor);
                  }
              }
          }
          return order;
      }
docs: Runs a breadth-first-search starting at the root node.