cout<<p->adjvertex<<" ";
p=p->nextarc;
}
cout<<endl;
}
}
template<class T>
void Graph<T>::DFS(int v,int visited[]){
if(v>vertexNum){ cout<<"顶点数处错误"<<endl; exit(0);}
Edge *p;
int j;
cout<<adjlist[v].vex<<" ";
visited[v]=1;
p=adjlist[v].firstarc;
while (p!=NULL) //依次搜索顶点v的邻接点j {
j=p->adjvertex;
if (visited[j]==0) DFS(j,visited);
p=p->nextarc;
}
}
void main()
{
char a[5]={'A','B','C','D','E'};
Graph<char> graph1(a,5,8);
graph1.printGraph();
int visited[5]={0};
graph1.DFS(2,visited);
}