BFS.h
#pragma once
//广度优先遍历
#include"Graph.h"
#include<queue>
#include<iostream>
vector<Node*>BFS(Graph graph, int start)
{
vector<Node*>res;
unordered_set<Node*>marked;//标记集合
queue<Node*>que;
//将起始点放入到队列中并且添加标记
que.push(graph.nodes[start]);
marked.insert(graph.nodes[start]);
while (!que.empty())
{
//弹出队列的首元素并且放入结果集中或者直接打印
Node* front = que.front();
que.pop();
cout << (char)front->val << " ";
res.push_back(front);
for (int i = 0; i < front->next.size(); i++)
{
if (marked.find(front->next[i]) == marked.end())
{
que.push(front->next[i]);
marked.insert(front->next[i]);
}