#include using namespace std; const int MaxVnum=100;//顶点数最大值 bool visited[MaxVnum]; //访问标志数组,其初值为"false" typedef char VexType;//顶点的数据类型为字符型 typedef struct AdjNode{ //定义邻接点类型 int v; //邻接点下标 struct AdjNode *next; //指向下一个邻接点 }AdjNode; typedef struct VexNode{ //定义顶点类型 VexType data; // VexType为顶点的数据类型,根据需要定义 AdjNode *first; //指向第一个邻接点 }VexNode; typedef struct{//定义邻接表类型 VexNode Vex[MaxVnum]; int vexnum,edgenum; //顶点数,边数 }ALGragh; int locatevex(ALGragh G,VexType x) { for(int i=0;iv=j; s->next=G.Vex[i].first; G.Vex[i].first=s; } void printg(ALGragh G)//输出邻接表 { cout<<"----------邻接表如下:----------"<v<<"] "; t=t->next; } cout<>G.vexnum>>G.edgenum; cout<<"请输入顶点信息:"<>G.Vex[i].data; for(i=0;i>u>>v; i=locatevex(G,u);//查找顶点u的存储下标 j=locatevex(G,v);//查找顶点v的存储下标 if(i!=-1&&j!=-1) { insertedge(G,i,j); insertedge(G,j,i);//无向图多插入一条边 } else { cout << "输入顶点信息错!请重新输入!"<v;//w为v的邻接点 if(!visited[w])//w未被访问 DFS_AL(G,w);//从w出发,递归深度优先遍历 p=p->next; } } void DFS_AL(ALGragh G)//非连通图,基于邻接表的深度优先遍历 { for(int i=0;i>c; v=locatevex(G,c);//查找顶点u的存储下标 if(v!=-1) { cout << "深度优先搜索遍历连通图结果:" <