正文之前
好久沒弄C++了绑榴,上學(xué)期頹廢了半學(xué)期,這學(xué)期開學(xué)就搞課程設(shè)計快瘋了拴曲。待會要考試CSP窗骑,所以弄點(diǎn)代碼儲備,待會到了考場說不定能省點(diǎn)功夫耳鸯!
正文
#include <iostream>
#include<queue>
#define Max 1000
using namespace std;
struct Graph
{
int a[10][10];
};
bool visited[10];
queue<int> path;
int width=0;
void BFS(Graph tu,int start)
{
visited[start]=true;
path.push(start);
while(path.size()!=0)
{
int top=path.front();
path.pop();
visited[top]=true;
cout<<top<<endl;
for(int i=0;i<10;++i)
{
if(tu.a[top][i]!=Max && visited[i]==false)
{
visited[i]=true;
path.push(i);
}
}
}
}
int main()
{
Graph tu;
for(auto &s:tu.a)
for(auto &x:s)
x=Max;
int a,b;
for(auto &s:visited)
s=false;
for(int i=0;i<8;++i)
{
cin>>a>>b;
tu.a[a][b]=tu.a[b][a]=1;
}
BFS(tu,1);
}
Output:
Last login: Sun Mar 18 11:46:37 on ttys000
= * = * = * = * = * = * = * = * = * = * = * = * = * = *
???(ˊ?ˋ)??* Hello湿蛔! Welcome 張照博!县爬!開啟愉快的一天吧阳啥!
= * = * = * = * = * = * = * = * = * = * = * = * = * = *
/Users/zhangzhaobo/program/C++/BFS ; exit;
HustWolf:~ zhangzhaobo$ /Users/zhangzhaobo/program/C++/BFS ; exit;
1 4 1 3 1 5 2 5 2 3 4 5 5 6 5 7
1
3
4
5
2
6
7
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[進(jìn)程已完成]
正文之后
祝我好運(yùn)!發(fā)誓這次考試后一定苦學(xué)财喳!上學(xué)期太飄了察迟。