Non-recursive Version of DFS Algorithm

来源:互联网 发布:ubuntu系统介绍 编辑:程序博客网 时间:2024/05/06 16:29

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.

 

 

原创粉丝点击