图的更多相关算法-4(测试)

 此篇是测试前面几篇的main函数。

 

 

  
  
  
  
  1. #include "graph.h" 
  2. #include "smallestree.h" 
  3. #include "shortestpath.h" 
  4. #include "topsort.h" 
  5. #define NUM 11 
  6. void main() 
  7.     MGraph mg; 
  8.     AGraph *ag = NULL; 
  9.     int A[MAXSIZE][MAXSIZE] = { 
  10.         {0,1,1,1},{1,0,0,0},{1,0,0,1},{1,0,1,0}                         //0 表示不可直接到达 
  11.     }; 
  12.     int A1[MAXSIZE][MAXSIZE] = { 
  13.         {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} 
  14.     }; 
  15.     int A2[MAXSIZE][MAXSIZE] = { 
  16.         {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} 
  17.     }; 
  18.     int A3[MAXSIZE][MAXSIZE] = { 
  19.         {0,5,0,7},{0,0,4,2},{3,3,0,2},{0,0,1,0}                         //0 表示不可直接到达 
  20.     }; 
  21.     int A4[MAXSIZE][MAXSIZE] = { 
  22.         {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} 
  23.     }; 
  24.     int A5[MAXSIZE][MAXSIZE] =  
  25.     { 
  26.         {0,3,4,0,0,0,0,0,0,0,0}, 
  27.         {0,0,0,2,1,0,0,0,0,0,0}, 
  28.         {0,0,0,0,3,5,0,0,0,0,0}, 
  29.         {0,0,0,0,0,0,6,0,0,0,0}, 
  30.         {0,0,0,0,0,0,8,4,0,0,0}, 
  31.         {0,0,0,0,0,0,0,0,2,0,0}, 
  32.         {0,0,0,0,0,0,0,0,0,0,7}, 
  33.         {0,0,0,0,0,0,0,0,10,4,0}, 
  34.         {0,0,0,0,0,0,0,0,0,1,0}, 
  35.         {0,0,0,0,0,0,0,0,0,0,6}, 
  36.         {0,0,0,0,0,0,0,0,0,0,0} 
  37.     }; 
  38.     //{0,1,0,1},{1,0,1,0},{0,1,0,0},{1,1,0,0} 
  39.     //{0,1,1,1},{1,0,0,0},{1,0,0,0},{1,0,0,0} 
  40. //  CreateMat(mg,A,NUM); 
  41. //  CreateMat(mg,A1,NUM); 
  42. //  CreateMat(mg,A2,NUM); 
  43. //  CreateMat(mg,A3,NUM); 
  44. /*  DispMat(mg); 
  45.     cout<<endl;  
  46.     InDs1(mg); 
  47.     OutDs1(mg);*/ 
  48.     CreateAdj(ag,A5,NUM);    
  49. //  DispAdj(ag); 
  50.  /* InDs(ag); 
  51.     OutDs(ag); 
  52.     MaxOutDs(ag);*/ 
  53.  
  54. //  DFS(ag,0); 
  55. //  cout<<endl; 
  56. //  DFS1(ag); 
  57.  
  58. //  BFS2(ag,0); 
  59. //  cout<<endl; 
  60. //  BFS1(ag); */                      //在调用DFS1或者BFS1之前要先调用DFS或者BFS,因为前者需要用后者改变后的visited数组 
  61. //  DFSX(ag,0);                         //此函数是广度遍历 
  62. //  DFSX2(ag,0);                        //此函数会颠倒顺序 
  63. //  DFSX3(ag,0);                    //此函数不行 
  64. //  maxdist2(ag,0); 
  65. //  isTree2(ag);     
  66. //  int path[MAXSIZE]; 
  67. //  PathAll4(ag,0,3,path,-1,2); 
  68. //  cycle(mg,0,0,-1,path); 
  69. //  ListToMat(mg, ag); 
  70. //  cout<<"max node num : "<<maxdist(ag,2)<<endl; 
  71. //  cout<<ag->e<<' '<<ag->n<<endl; 
  72. //  if(isTree(ag)) cout<<"it is a tree!"<<endl;               //在判断图是否为一个树的时候,这个图一定是一个无向图 
  73. //  else cout<<"not a tree"<<endl; 
  74. //  cout<<nodes(ag)<<endl; 
  75. //  if(isAPath(ag,0,3)) cout<<"have a path"<<endl; 
  76. //  else cout<<"not a path"<<endl; 
  77. //  if(DHaveAPath3(ag,0,2)) cout<<"have a path"<<endl; 
  78. //  else cout<<"not have a path"<<endl; 
  79. //  int path[MAXSIZE]; 
  80. /*  int path2[MAXSIZE]; 
  81.     PathAll(ag,0,2,path,-1,1); 
  82.     PathAll2(ag,path2,0,2); */ 
  83. //  PathAll3(mg,0,1,path); 
  84. //  cout<<"Root is "<<DGRoot2(mg)<<endl; 
  85. //  TravPath(ag,0,3,path); 
  86.  
  87.  
  88.  
  89.  
  90. //  Prim(mg,0); 
  91. //  Krusakl(mg); 
  92. //  Dijkstra(mg,0); 
  93. //  Floyd(mg); 
  94. //  MinTree(mg,0); 
  95. //  Centerp(mg); 
  96. //  int topsq[MAXSIZE]; 
  97. //  TopSort(ag,topsq); 
  98. //  TopSort2(ag,topsq); 
  99. //  dfs_topsort(ag); 
  100.  
  101.  
  102.     CriticalPath(ag); 

 

你可能感兴趣的:(算法,测试,图)