17.广度优先遍历bfs
2024-08-31 12:46:32
#include <iostream>
#include <boost/config.hpp>
//图(矩阵实现)
#include <boost/graph/adjacency_matrix.hpp>
#include <boost\graph\graph_utility.hpp>
#include <boost/graph/graph_traits.hpp>
//图(链表实现)
#include <boost/graph/adjacency_list.hpp>
//求最小生成树
#include <boost/graph/kruskal_min_spanning_tree.hpp>
//prim算法求最小生成树
#include <boost/graph/prim_minimum_spanning_tree.hpp>
//深度优先遍历
#include<boost/graph/depth_first_search.hpp>
//广度优先遍历
#include <boost/graph/breadth_first_search.hpp>
using namespace std;
using namespace boost; //顶点名称
enum { A, B, C, D, E, F, G, H ,I};
//顶点个数
#define N 8
const char *name = "ABCDEFGH"; //宏定义
typedef adjacency_list<vecS, vecS, undirectedS, no_property, property<edge_weight_t, int>> mygraph;
typedef property<edge_weight_t, int> EWP; class BFSmyv :public boost::default_bfs_visitor
{
public:
//当前在哪个结点
template<typename vertex,typename Graph>
void discover_vertex(vertex v, Graph g) const
{
cout << "at" << v << endl;
} //输出当前结点下一个要访问的结点
template<typename Edge,typename Graph> const
void examine_edge(Edge e, Graph g)
{
cout << "edges" << e << endl;
}
}; //无向图
void main()
{
//图,每个结点是vec来实现,无向图,有边长与权重的属性
mygraph myg;
add_edge(A, B,, myg);
add_edge(B, C, ,myg);
add_edge(A, C,, myg);
add_edge(A, D,, myg);
add_edge(C, D,, myg);
add_edge(D, E,, myg);
add_edge(E, F, , myg);
add_edge(B, E, , myg);
add_edge(B, F, , myg);
add_edge(B, G, , myg);
add_edge(B, H, , myg);
add_edge(B, I, , myg); adjacency_list<vecS, vecS, undirectedS, no_property, property<edge_weight_t, int>>test;
BFSmyv myd; //用于广度优先遍历
//mygraph test;
breadth_first_search(myg,vertex(,test), visitor(myd)); cin.get();
}
最新文章
- python基础(八)面向对象的基本概念
- Elasticsearch聚合 之 Ip Range IP地址范围聚合
- SVN使用教程总结
- FBI是如何破获“美国少女”裸照勒索案的
- .NET Core常用配置文件示例
- fork/join使用示例
- 【部分枚举】【3-21个人赛】ProblemH
- WCF 启用multipleSiteBindingsEnabled 情况下报终结点地址错误
- 有了SSL证书,如何在IIS环境下部署https?【转载】
- MVC和三层架构
- 【Java】java 中的泛型通配符——从“偷偷地”地改变集合元素说起
- 爬坑二 activiti流数据库版本错误引发的问题
- Tasklist使用详解
- word2vec skip-gram系列2
- C166 -MDH
- linux网络设备—mdio总线
- 10.16JS日记
- 电子邮件-TCP
- Integer.parseInt() 和 valueOf()
- js的form表单提交url传参数(包含+等特殊字符)的解决方法