Bellman–Ford algorithm: Difference between revisions

Content deleted Content added
vertex.predecessor doesn't make any sense -- v.predecessor, right?
Line 77:
void BellmanFord(Edge edges[], size_t edgecount, size_t nodecount, size_t source)
{
int i,j ;
int* distance = (int*) malloc(nodecount*sizeof(int));
for(int i = 0; i < nodecount; i++)
{
if(i == source) distance[i] = 0;
else distance[i] = INFINITY;
}
for(int i = 0; i < nodecount; i++)
{
for(int j = 0; j < edgecount; j++)
{
if(distance[edges[j].dest] > distance[edges[j].source] + edges[j].weight)
Line 101 ⟶ 102:
}
}
for(int i = 0; i < nodecount; i++)
{
printf("The shortest distance between nodes %i and %i is %i", source, i, distance[i]);