1+ #include < iostream>
2+ #include " SparseGraph.h"
3+ #include " DenseGraph.h"
4+ #include " ReadGraph.h"
5+ #include " Components.h"
6+
7+ using namespace std ;
8+
9+ // 测试图的联通分量算法
10+ int main () {
11+ // TestG1.txt : G1 and G2
12+ string filename1 = " testG1.txt" ;
13+ SparseGraph g1 = SparseGraph (13 , false );
14+ ReadGraph<SparseGraph> readGraph1 (g1, filename1);
15+ Component<SparseGraph> component1 (g1);
16+ cout<<" TestG1.txt, Using Sparse Graph, Component Count: " <<component1.count ()<<endl;
17+
18+ DenseGraph g2 = DenseGraph (13 , false );
19+ ReadGraph<DenseGraph> readGraph2 (g2, filename1);
20+ Component<DenseGraph> component2 (g2);
21+ cout<<" TestG1.txt, Using Dense Graph, Component Count: " <<component2.count ()<<endl;
22+
23+ cout<<endl;
24+
25+ // TestG2.txt : G3 and G4
26+ string filename2 = " testG2.txt" ;
27+ SparseGraph g3 = SparseGraph (7 , false );
28+ ReadGraph<SparseGraph> readGraph3 (g3, filename2);
29+ Component<SparseGraph> component3 (g3);
30+ cout<<" TestG2.txt, Using Sparse Graph, Component Count: " <<component3.count ()<<endl;
31+
32+ DenseGraph g4 = DenseGraph (7 , false );
33+ ReadGraph<DenseGraph> readGraph4 (g4, filename2);
34+ Component<DenseGraph> component4 (g4);
35+ cout<<" TestG2.txt, Using Dense Graph, Component Count: " <<component4.count ()<<endl;
36+
37+ return 0 ;
38+ }
0 commit comments