此篇是测试前面几篇的main函数。
- #include "graph.h"
- #include "smallestree.h"
- #include "shortestpath.h"
- #include "topsort.h"
- #define NUM 11
- void main()
- {
- MGraph mg;
- AGraph *ag = NULL;
- int A[MAXSIZE][MAXSIZE] = {
- {0,1,1,1},{1,0,0,0},{1,0,0,1},{1,0,1,0} //0 表示不可直接到达
- };
- int A1[MAXSIZE][MAXSIZE] = {
- {0,6,1,5,0,0},{6,0,5,0,3,0},{1,5,0,5,6,4},{5,0,5,0,0,2},{0,3,6,0,0,6},{0,0,4,2,6,0}
- };
- int A2[MAXSIZE][MAXSIZE] = {
- {0,4,6,6,0,0,0},{0,0,1,0,7,0,0},{0,0,0,0,6,4,0},{0,0,2,0,0,5,0},{0,0,0,0,0,0,6},{0,0,0,0,1,0,8},{0,0,0,0,0,0,0}
- };
- int A3[MAXSIZE][MAXSIZE] = {
- {0,5,0,7},{0,0,4,2},{3,3,0,2},{0,0,1,0} //0 表示不可直接到达
- };
- int A4[MAXSIZE][MAXSIZE] = {
- {0,6,4,5,0,0,0},{0,0,0,0,1,0,0},{0,0,0,0,1,0,0},{0,0,0,0,0,2,0},{0,0,0,0,0,0,7},{0,0,0,0,0,0,4},{0,0,0,0,0,0,0}
- };
- int A5[MAXSIZE][MAXSIZE] =
- {
- {0,3,4,0,0,0,0,0,0,0,0},
- {0,0,0,2,1,0,0,0,0,0,0},
- {0,0,0,0,3,5,0,0,0,0,0},
- {0,0,0,0,0,0,6,0,0,0,0},
- {0,0,0,0,0,0,8,4,0,0,0},
- {0,0,0,0,0,0,0,0,2,0,0},
- {0,0,0,0,0,0,0,0,0,0,7},
- {0,0,0,0,0,0,0,0,10,4,0},
- {0,0,0,0,0,0,0,0,0,1,0},
- {0,0,0,0,0,0,0,0,0,0,6},
- {0,0,0,0,0,0,0,0,0,0,0}
- };
- //{0,1,0,1},{1,0,1,0},{0,1,0,0},{1,1,0,0}
- //{0,1,1,1},{1,0,0,0},{1,0,0,0},{1,0,0,0}
- // CreateMat(mg,A,NUM);
- // CreateMat(mg,A1,NUM);
- // CreateMat(mg,A2,NUM);
- // CreateMat(mg,A3,NUM);
- /* DispMat(mg);
- cout<<endl;
- InDs1(mg);
- OutDs1(mg);*/
- CreateAdj(ag,A5,NUM);
- // DispAdj(ag);
- /* InDs(ag);
- OutDs(ag);
- MaxOutDs(ag);*/
- // DFS(ag,0);
- // cout<<endl;
- // DFS1(ag);
- // BFS2(ag,0);
- // cout<<endl;
- // BFS1(ag); */ //在调用DFS1或者BFS1之前要先调用DFS或者BFS,因为前者需要用后者改变后的visited数组
- // DFSX(ag,0); //此函数是广度遍历
- // DFSX2(ag,0); //此函数会颠倒顺序
- // DFSX3(ag,0); //此函数不行
- // maxdist2(ag,0);
- // isTree2(ag);
- // int path[MAXSIZE];
- // PathAll4(ag,0,3,path,-1,2);
- // cycle(mg,0,0,-1,path);
- // ListToMat(mg, ag);
- // cout<<"max node num : "<<maxdist(ag,2)<<endl;
- // cout<<ag->e<<' '<<ag->n<<endl;
- // if(isTree(ag)) cout<<"it is a tree!"<<endl; //在判断图是否为一个树的时候,这个图一定是一个无向图
- // else cout<<"not a tree"<<endl;
- // cout<<nodes(ag)<<endl;
- // if(isAPath(ag,0,3)) cout<<"have a path"<<endl;
- // else cout<<"not a path"<<endl;
- // if(DHaveAPath3(ag,0,2)) cout<<"have a path"<<endl;
- // else cout<<"not have a path"<<endl;
- // int path[MAXSIZE];
- /* int path2[MAXSIZE];
- PathAll(ag,0,2,path,-1,1);
- PathAll2(ag,path2,0,2); */
- // PathAll3(mg,0,1,path);
- // cout<<"Root is "<<DGRoot2(mg)<<endl;
- // TravPath(ag,0,3,path);
- // Prim(mg,0);
- // Krusakl(mg);
- // Dijkstra(mg,0);
- // Floyd(mg);
- // MinTree(mg,0);
- // Centerp(mg);
- // int topsq[MAXSIZE];
- // TopSort(ag,topsq);
- // TopSort2(ag,topsq);
- // dfs_topsort(ag);
- CriticalPath(ag);
- }