w QueueList; Q->front=Q->rear=NULL; EnQueue(Q,v); while(Q->rear!=NULL) { int e=0; DeQueue(Q,&e); cout<<G->adjlists[e].vertex<<" "; visit[e]=1; edgenode* p=new edgenode; p=G->adjlists[e].edgelink; if(p) { int m=p->endver; if(m==0) { EnQueue(Q,m); while(visit[m]==0) { p=p->edgenext; if(p==NULL) break; m=p->endver; EnQueue(Q,m); }}}}} void BFStraversal(Graph *G,char c) { cout<<" 该图的广度优先遍历结果为:"<<endl; int visited[MaxVerNum]; for (int i=0;i<G->vexnum;i++) { visited[i]=0; } int m; for (i=0;i<G->vexnum;i++) { if (G->adjlists[i].vertex==c) { m=i; BFS(G,i,visited); break; }} // 继续访问未被访问的结点 for(i=0;i<G->vexnum;i++) { if(visited[i]==0) BFS(G,i,visited); } cout<<endl; } void main() { Graph * G=new Graph; CreatAdjList(G); char ch; cout<<" 请输入开始遍历的顶点:"; cin>>ch; DFStraversal(G,ch); BFStraversal(G,ch); }