#include
#include
//图(矩阵实现)
#include
#include
#include
//图(链表实现)
#include
//求最小生成树
#include
using namespace std;
using namespace boost;
//顶点名称
enum { A, B, C, D, E, F };
//顶点个数
#define N 6
const char *name = "ABCDEF";
//无向图
void main()
{
//图,每个结点是vec来实现,无向图,有边长与权重的属性
adjacency_list
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(B, D,, myg);
//链表
typedef adjacency\_list<vecS, vecS, undirectedS, property<edge\_weight\_t, int>> mygraph;
//创建边的链表
list<mygraph::edge\_descriptor> mylist;
//生成的结果尾插到mylist
kruskal\_minimum\_spanning\_tree(myg, back\_inserter(mylist));
//创建边与权重的映射(weight是函数指针)
auto weight= get(edge\_weight,myg);
//property\_map<mygraph, edge\_weight\_t>::type weight = get(edge\_weight, myg);
for (auto ib = mylist.begin(); ib != mylist.end(); ib++)
{
//输出边
//cout << \*ib << endl;
cout << source(\*ib, myg) << "->" << target(\*ib, myg) << "权重" << weight(\*ib) << endl;
}
cin.get();
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章