我有深度优先搜索算法,其伪代码如下:
DFS(Vertex v)
mark v visited
make an empty Stack S
push all vertices adjacent to v onto S
while S is not empty do
Vertex w is pop off S
for all Vertex u adjacent to w do
if u is not visited then
mark u visited
push u onto S
现在,我希望将上述 dfs 算法转换为广度优先搜索。我正在用 C++ 实现该程序。我不知道如何去做同样的事情。
编辑:我知道 bfs 的伪代码。我正在寻找的是如何将上述dfs的伪代码转换为bfs。