int Graph BFS bool visited int unit int point bool flag int int queue

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
int Graph::BFS(bool *visited, int unit, int point, bool* flag, int k)
{
int *queue=new int[n];
int count=0, head=0,i,j;
for (i=0; i<n; i++)
queue[i]=0;
queue[count++]=unit;
visited[unit]=true;
while (head<count)
{
unit=queue[head++];
if ((unit+1)==point)
flag[k]=1;
cout«unit+1«" ";
for (i=0; i<n; i++)
if (GM[unit][i] && !visited[i])
{
queue[count++]=i;
visited[i]=true;
}
}