图论
图的遍历
DFS
void DFS(Graph G,int v)
{
visited[v] = True;
VisitFunc();//operate to vertex that you want visite
for(w = FirstAdjVex(G,V); w >= 0; w = NextAdjVex(G,v,w))// search for the vertex that are adjacent to v
{
if(!visited[w]) DFS(G,W);// if w is not visited, then visited it.
}
}
BFS
void BFS(Graph G,int v)
{
memset(v,False,sizeof(v));
InitQueue();
for(v = 0; v < G.vexnum; ++v)
{
if(!visited[v])
{
visited[v] = TRUE;
visit(v);
Enqueue(Q,u);
}
}
}