12.boost有向图无向图(矩阵法)
1 #include <iostream> 2 #include <boost/config.hpp> 3 //图 4 #include <boost/graph/adjacency_matrix.hpp> 5 #include <boost\graph\graph_utility.hpp> 6 7 using namespace std; 8 using namespace boost; 9 10 //顶点名称 11 enum { A, B, C, D, E, F }; 12 //顶点个数 13 #define N 6 14 const char *name = "ABCDEF"; 15 16 //无向图 17 void main1() 18 { 19 adjacency_matrix<undirectedS> myg(N); 20 add_edge(A, B, myg); 21 add_edge(A, C, myg); 22 add_edge(A, D, myg); 23 add_edge(A, E, myg); 24 add_edge(B, C, myg); 25 add_edge(F, C, myg); 26 27 cout << "顶点" << endl; 28 print_vertices(myg, name); 29 cout << endl; 30 31 cout << "边" << endl; 32 print_edges(myg, name); 33 cout << endl; 34 35 cout << "关联" << endl; 36 print_graph(myg, name); 37 cout << endl; 38 39 cin.get(); 40 } 41 42 //有向图 43 void main2() 44 { 45 adjacency_matrix<directedS> myg(N); 46 add_edge(A, B, myg); 47 add_edge(A, C, myg); 48 add_edge(A, D, myg); 49 add_edge(A, E, myg); 50 add_edge(B, C, myg); 51 add_edge(F, C, myg); 52 53 cout << "顶点" << endl; 54 print_vertices(myg, name); 55 cout << endl; 56 57 cout << "边" << endl; 58 print_edges(myg, name); 59 cout << endl; 60 61 cout << "关联" << endl; 62 print_graph(myg, name); 63 cout << endl; 64 cin.get(); 65 }