I want to find any path (just one path is enough and it doesn't matter which one) and I want to find the sum of edge weights too. I used bfs for this problem but I can't get the right path. Here is my code. Can someone please help me and tell me where my errors are? Thanks!
int bfs(struct Graph* graph, int startVertex,int endVertex) {
struct queue* q = createQueue();
int totalweight=0;
graph->visited[startVertex] = 1;
enqueue(q, startVertex);
while (!isEmpty(q)) {
int currentVertex = dequeue(q);
if(currentVertex==endVertex){
return;
}
struct node* temp = graph->adjLists[currentVertex];
totalweight+=temp->weight;
int adjVertex ;
while (temp) {
adjVertex = temp->vertex;
if (graph->visited[adjVertex] == 0) {
graph->visited[adjVertex] = 1;
enqueue(q, adjVertex);
}
temp = temp->next;
}
printf("%d ",adjVertex);
}
return totalweight;
}