Skip to content

Commit c02a1c5

Browse files
committed
forgot to stage bfs ._.
1 parent 27bfc4b commit c02a1c5

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

bfs.c

+18-6
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ void theWay(graph* g,int distToSource[], int lasts[],int origin, int destination
135135
int buffer[distToSource[destination]];
136136
//printf("[[%d]]\n",distToSource[destination]);
137137
int i = 0;
138+
138139
while (pass != origin)
139140
{
141+
DEBUG printf("ORIGEM: [%d]\t",origin);
142+
DEBUG printf("ultimo de [%d] = [%d]\n",i,lasts[i]);
140143
buffer[i] = lasts[pass];
141144
pass = lasts[pass];
142145
i++;
@@ -155,8 +158,7 @@ void bfs(graph* graph,int origin, int destination, int count)
155158
{
156159
graph->visited[i] = 0;
157160
}
158-
159-
int verticesNum = count;
161+
int verticesNum = count; count = 0;
160162
adj_list* tmp = graph->vertices[origin];
161163
Queue* queue = initQ();
162164
int dequeued;
@@ -168,7 +170,6 @@ void bfs(graph* graph,int origin, int destination, int count)
168170
distToSource[origin] = 0;
169171
int lasts[MAX_SIZE]; //vai guardar qual o pai do index... se 3 é pai de 2, lasts[2] = 3
170172
int found = 0;
171-
count = 0;
172173
while (!isEmptyQ(queue))
173174
{
174175
dequeued = deQueue(queue); //dequeued é o numero que vai ser visitado,
@@ -182,19 +183,25 @@ void bfs(graph* graph,int origin, int destination, int count)
182183
enQueue(queue,tmp->item);
183184
lasts[tmp->item] = dequeued;
184185
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]);
186188
}
187189
else
188190
{
189191
tmp = tmp->next;
192+
DEBUG printf("FINIS ___ ultimo de [%d] = [%d]\n",count,lasts[count]);
190193
continue;
191194
}
192195
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+
}
194201
if(tmp->item == destination)
195202
{
196203
found = 1;
197-
//DEBUG printf("encontrado [%d]!", found);
204+
DEBUG printf("encontrado [%d]!\t", found);
198205
//DEBUG printf("ENCONTRADO depois de %d passagens, ultimo foi [%d]\n",count,lasts[count-1]);
199206
//break;
200207
}
@@ -204,6 +211,11 @@ void bfs(graph* graph,int origin, int destination, int count)
204211

205212
}
206213
//node_explanation(graph);
214+
DEBUG for (int i = 0; i < count; i++)
215+
{
216+
printf("LAST[%d] = [[%d]]\n",i,lasts[i]);
217+
}
218+
207219
printf("\n");
208220
for (int i = 0; i < verticesNum; i++)
209221
{

0 commit comments

Comments
 (0)