@@ -135,8 +135,11 @@ void theWay(graph* g,int distToSource[], int lasts[],int origin, int destination
135
135
int buffer [distToSource [destination ]];
136
136
//printf("[[%d]]\n",distToSource[destination]);
137
137
int i = 0 ;
138
+
138
139
while (pass != origin )
139
140
{
141
+ DEBUG printf ("ORIGEM: [%d]\t" ,origin );
142
+ DEBUG printf ("ultimo de [%d] = [%d]\n" ,i ,lasts [i ]);
140
143
buffer [i ] = lasts [pass ];
141
144
pass = lasts [pass ];
142
145
i ++ ;
@@ -155,8 +158,7 @@ void bfs(graph* graph,int origin, int destination, int count)
155
158
{
156
159
graph -> visited [i ] = 0 ;
157
160
}
158
-
159
- int verticesNum = count ;
161
+ int verticesNum = count ; count = 0 ;
160
162
adj_list * tmp = graph -> vertices [origin ];
161
163
Queue * queue = initQ ();
162
164
int dequeued ;
@@ -168,7 +170,6 @@ void bfs(graph* graph,int origin, int destination, int count)
168
170
distToSource [origin ] = 0 ;
169
171
int lasts [MAX_SIZE ]; //vai guardar qual o pai do index... se 3 é pai de 2, lasts[2] = 3
170
172
int found = 0 ;
171
- count = 0 ;
172
173
while (!isEmptyQ (queue ))
173
174
{
174
175
dequeued = deQueue (queue ); //dequeued é o numero que vai ser visitado,
@@ -182,19 +183,25 @@ void bfs(graph* graph,int origin, int destination, int count)
182
183
enQueue (queue ,tmp -> item );
183
184
lasts [tmp -> item ] = dequeued ;
184
185
distToSource [tmp -> item ] = distToSource [dequeued ]+ 1 ;
185
- //DEBUG printQ(queue,graph);
186
+ DEBUG printQ (queue ,graph );
187
+ DEBUG printf ("ultimo de [%d] = [%d]\n" ,count ,lasts [count ]);
186
188
}
187
189
else
188
190
{
189
191
tmp = tmp -> next ;
192
+ DEBUG printf ("FINIS ___ ultimo de [%d] = [%d]\n" ,count ,lasts [count ]);
190
193
continue ;
191
194
}
192
195
printf ("Iniciando busca em largura a partir de %d\n" ,tmp -> item );
193
- if (found == 0 ){ lasts [count ] = tmp -> item ; count ++ ;}
196
+ if (found == 0 )
197
+ {
198
+ DEBUG printf ("\t count++\n" );
199
+ count ++ ;
200
+ }
194
201
if (tmp -> item == destination )
195
202
{
196
203
found = 1 ;
197
- // DEBUG printf("encontrado [%d]!", found);
204
+ DEBUG printf ("encontrado [%d]!\t " , found );
198
205
//DEBUG printf("ENCONTRADO depois de %d passagens, ultimo foi [%d]\n",count,lasts[count-1]);
199
206
//break;
200
207
}
@@ -204,6 +211,11 @@ void bfs(graph* graph,int origin, int destination, int count)
204
211
205
212
}
206
213
//node_explanation(graph);
214
+ DEBUG for (int i = 0 ; i < count ; i ++ )
215
+ {
216
+ printf ("LAST[%d] = [[%d]]\n" ,i ,lasts [i ]);
217
+ }
218
+
207
219
printf ("\n" );
208
220
for (int i = 0 ; i < verticesNum ; i ++ )
209
221
{
0 commit comments