(三)圖的遍歷
Boolean Visited[AX];
Status(*visitFunc)(intv);
Void DFSTraverse(Graph G
VisitFunc=Visit;
For(v=
For(v=
If(!visited[v]) DFS)g
}
Void DFS(Graph G
Visited[v]=true; visitFunc(v);
for(w=FirstAdjVex(G
if(!visited[w]) DFS(G
}
void BFSTraverse(Graph G
//按廣度優先非遞歸遍歷圖
for(V=
InitQueue(Q);
for(v=
if(!visited[v]){
visited[v]=TRUE; visit(v);
ENQUEUE(Q<V);
while(!QueueEmpty(Q)){
deQueue(Q
for(W=firstAdjVex(g
if(!Visited[w]){
Visited[w]=TuRE; Visit(w);
ENQueue(Q
}//if
}//while
}//if
}//BFSTraverse
返回《數據結構》考研復習精編
[
From:http://tw.wingwit.com/Article/program/sjjg/201311/23291.html