DFS is the most important graph traversal algorithm and has been adopted as the default traversal module for many software system. In this article, the non-recursive implementation of DFS in C++ is given. The basic idea is to record the vertexes during traversal by utilizing a stack, and decide whether a vertex need to be pushed into the stack according to a mark array which indicate whether the current vertex has been visited.
本文介绍了一种采用栈和标记数组实现的非递归深度优先搜索(DFS)算法,并给出了C++的具体实现代码。该算法适用于邻接矩阵表示的图,通过遍历顶点并利用栈记录访问路径,确保每个顶点仅被访问一次。
1万+

被折叠的 条评论
为什么被折叠?



