Created
July 26, 2008 06:12
-
-
Save ashwin/2611 to your computer and use it in GitHub Desktop.
Example of boost DFS on an undirected graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Boost DFS example on an undirected graph. | |
#include <boost/graph/adjacency_list.hpp> | |
#include <boost/graph/depth_first_search.hpp> | |
#include <iostream> | |
using namespace std; | |
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> MyGraph; | |
typedef boost::graph_traits<MyGraph>::vertex_descriptor MyVertex; | |
class MyVisitor : public boost::default_dfs_visitor | |
{ | |
public: | |
void discover_vertex(MyVertex v, const MyGraph& g) const | |
{ | |
cerr << v << endl; | |
return; | |
} | |
}; | |
int main() | |
{ | |
MyGraph g; | |
boost::add_edge(0, 1, g); | |
boost::add_edge(0, 2, g); | |
boost::add_edge(1, 2, g); | |
boost::add_edge(1, 3, g); | |
MyVisitor vis; | |
boost::depth_first_search(g, boost::visitor(vis)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment