I've written the following code:
我写了以下代码:
void bfs(graph *g, int start)
{
int i;
int visited[MAXVERTS], next;
for (i = 0; i < g -> nodes; i++)
visited[i] = 0;
visited[start] = 1;
printf("%d", start);
queuePtr q;
q = QueueCreate();
QueueEnter(q,start);
while(!QueueIsEmpty(q))
{
next=QueueDelete(q);
node *p=g->adjList[next];
while(p)
{
if(!visited[p->index])
visited[p->index] = 1;
QueueEnter(q,p->index);
}
p=p->link;
}
}
What do I need to add to make it calculate the distance between two nodes in a graph? I've been trying and I can't get it to work.
我需要添加什么来计算图形中两个节点之间的距离?我一直在努力,我无法让它发挥作用。
1 个解决方案
#1
0
Well, I implemented that same code some time ago, but can't find it. Amyway, the Dijkstra's algorithm is what you need.
好吧,我前段时间实现了相同的代码,但找不到它。 Amyway,Dijkstra的算法就是你所需要的。
Cheers.
#1
0
Well, I implemented that same code some time ago, but can't find it. Amyway, the Dijkstra's algorithm is what you need.
好吧,我前段时间实现了相同的代码,但找不到它。 Amyway,Dijkstra的算法就是你所需要的。
Cheers.