//邻接表定义
typedef struct ArcNode{
int adjvex;
ArcNode* next;
}ArcNode;
typedf struct VNode{
int data;
ArcNode* firstarc;
}VNode;
typedef struct{
VNode adjlist[MAXSIZE];
int n,e;
}ALGraph;
//邻接矩阵存储结构
typedef struct{
int d[MAXSIZE];
int arcs[MAXSIZE][MAXSIZE];
int n,e;
}MGraph;
//DFS 深度优先遍历
bool visited[maxsize]={false};
void DFS(ALgrpah g,int v)
{
ArcNode *p;
visted[v]=true;
p=g.adjlist[v].firstarc;
while(p!=NULL)
{
if(visited[p->adjvex]==false)
{
DFS(g,p->adjvex);
}
p=p->next;
}
}
void dfs(ALGraph g)
{
for(int i=0;i<g.n;i++)
{
if(visited[i]==false) {DFS(g,i);}
}
}
//bfs 广度优先遍历
void BFS(ALGraph g,int v)
{
ArcNode *p;
visited[v]=true;
queue<int> q;
q.push(v);
while(!q.empty())
{
int w=q.front();
q.pop();
p=g.adjlist[w].firstarc;
while(p!=null)
{
if(visited[p->adjvex]==false)
{
visited[p->adjvex]=true;
q.push(p->adjvex);
}
p=p->next;
}
}
}
///
void bfs(ALgraph g)
{
for(int i=0;i<g.n;i++)
{
if(visited[i]==false) {BFS(g,i);}
}
}