标签:io os for sp on c ef size r
#include <iostream>
#include<vector>
#include<list>
#include<queue>
#include<algorithm>
using namespace std;
typedef vector<list<int> > Graph;
void bfs(Graph p)
{
bool visited[p.size()];
for(int i=0;i!=(int)p.size();i++)
{
visited[i]=false;
}
queue<int> que;
if(p.empty())
{
return;
}
que.push(0);
while(!que.empty())
{
int visiting_point=que.front();
que.pop();
if(!visited[visiting_point])
{
cout<<visiting_point<<endl;
visited[visiting_point]=true;
for(list<int>::iterator iter=p[visiting_point].begin();
iter!=p[visiting_point].end();iter++)
{
que.push(*iter);
}
}
}
}
int main()
{
Graph graph;
list<int> list0;
list0.push_back(2);
list<int> list1;
list1.push_back(2);
list<int> list2;
list2.push_back(0);
list2.push_back(1);
graph.push_back(list0);
graph.push_back(list1);
graph.push_back(list2);
bfs(graph);
return 0;
}
标签:io os for sp on c ef size r
原文地址:http://www.cnblogs.com/litengyao/p/3980630.html