1、#include#include#includetypedef int VertexType;typedef int WeightType;const int MaxVertexNum=10;const WeightType MaxValue=1000;typedef VertexType vexlistMaxVertexNum;typedef int adjmatrixMaxVertexNumMaxVertexNum;/1.图的邻接矩阵存储的初始化算法void InitMaxtrix(adjmatrix GA,int k)int i,j;for(i=0;ic1;if(k1=0 GAij=GA
2、ji=1;sinc1;if(c1=) break;while(1);else if(k1=0 GAij=GAji=w;sinc1;if(c1=) break;while(1);else if(k1!=0 GAij=1;sinc1;if(c1=) break;while(1);else if(k1!=0 GAij=w;sinc1;if(c1=) break;while(1);/3.根据图的邻接矩阵输出图的二元组表示(顶点和边集)的算法void PrintMaxtrix(adjmatrix GA,int n,int k1,int k2)int i,j;coutn;coutk1k2;bool*visited=new booln;adjmatrix ga;InitMaxtrix(ga,k2);couta;CreateMatrix(ga,n,a,k1,k2);cout“按图的邻接矩阵得到深度优先遍历序列:“endl;for(i=0;in;i+) visitedi=false;dfsMatrix(ga,0,n,visited);coutendl;cout“按图的邻接矩阵得到的广度优先遍历序列:“endl;for(i=0;in;i+) visitedi=false;bfsMatrix(ga,0,n,visited);coutendl;PrintMaxtrix(ga,n,k1,k2);