使用boost::edge_list的示例程序
在C++中,boost是一个很流行的开源库,它提供了很多功能强大的工具,特别是在图论领域中有很多好用的图算法。其中,edge_list是boost库中存储图数据的一种方式。它以边列表的形式存储图的信息,可以方便地进行图的遍历和修改。下面是一个使用boost::edge_list实现简单图遍历的示例程序:
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/edge_list.hpp>
using namespace boost;
using namespace std;
int main()
{
// 定义图的类型
typedef adjacency_list<vecS, vecS, undirectedS> Graph;
// 定义边列表
vector<pair<int, int>> edges = {
{0, 1}, {0, 2}, {1, 3}, {2, 3}, {2, 4},
{3, 5}, {4, 5}, {4, 6}, {5, 7}, {6, 7}};
// 从边列表中构造图
Graph g(edges.begin(), edges.end(), 8);
// 遍历图中的所有点
Graph::vertex_iter