=0;i<G->n;i++)Р?{Р if(!visited[i]) //Vi未访问过Р {Р DFST(G,i); //以Vi为源点开始DFS搜索Р }Р?}Р}Рvoid BFS(Graph *G)Р{ Р int i;Р?memset(visited,false,sizeof(visited));Р for(i=0;i<G->n;i++)Р?{Р if(!visited[i]) //Vi未访问过Р {Р BFST(G,i); //以Vi为源点开始DFS搜索Р }Р?}Р}Р//BFS:广度优先遍历Рvoid BFST(Graph *G,int k) //以Vk为源点对用邻接矩阵表示的图G进行广度优先搜索Р{ Р?queue<int > q;Р?int temp;Р?q.push(k);Р?visited[k] = true;Р?while (!q.empty())Р?{Р temp = q.front();Р q.pop();Р cout<<G->vexs[temp]<<" ";Р for (int j = 0; j < G->n; j++)Р {Р if (G->edges[temp][j] == 1 && !visited[j])Р {Р q.push(j);Р visited[j] = true;Р }Р }Р?}Р}Рvoid main()Р{Р Graph *G;Р G=(Graph *)malloc(sizeof(Graph)); //为图G申请内存空间Р CreatGraph(G); //建立邻接矩阵Р cout<<"Print Graph DFS: ";Р DFS(G); //深度优先遍历Р cout<<endl;Р cout<<"Print Graph BFS:";Р BFS(G); //以序号为3的顶点开始广度优先遍历Р cout<<endl;Р}