Home > Back-end >  BFS related issues
BFS related issues

Time:09-24


In BFS words such as how to do, I'm easy to write DFS, and if use BFS, how should I know mobile points, the following attached has hit the code
 # include 
# include
using namespace std;
Int a [10] [10]={{0,0,0,0,0,0,0,0,0,0},
,0,0,0,1,1,1,0,0,0 {0},
,0,0,0,1,0,0,1,0,0 {0},
,0,0,0,0,1,0,0,1,0 {0},
,0,1,0,0,0,1,0,1,0 {0},
,1,0,1,0,1,0,0,1,0 {0},
,1,0,0,1,1,0,1,1,0 {0},
,0,1,0,0,0,0,1,0,0 {0},
,0,0,1,1,1,1,0,0,0 {0},
,0,0,0,0,0,0,0,0,0 {0}};
Int x [4]={1, 0, 1, 0};
Int y [4]={0, 0, 1};
Queue Q;
Int the x1=0, y1=0, tempx=0, tempy=0;
Int main () {
Q.p ush (a [0] [0]).
while(! Q.t emp ()) {

C=q.f ront (); Q.p op ();
A [x1] [y1]=1;
for(int i=0; I<4. I++) {
If (x1 + x [I] & gt; 1 & amp; & The x1 + x [I] <10 & amp; & Y1 + y [I] & gt; 1 & amp; & Y1 + y [I] <10 & amp; & (! A [x1 + x [I]] [y1 + y [I]]) {

}
}
}
return 0;
}
  • Related