Hello, this is my first C program and the first time I have posted here.. or anywhere for code help.
My issue is in my understanding of the dijkstra algorithm. I get the talked-out version.. and have read many different explanations. I thought I had it straight.. but after coding it, it's wrong.
Code:
void dijkstra(char start[MAXLENGTH]){
int startInt;
int endInt;
int s[MAXLENGTH];
int min = -1;
int z = 0;
for(z = 0; z <= count; ++z){
d[z] = MAXINT;
s[z] = 0;
}
endInt = cityToInt(end);
startInt = cityToInt(start);
d[startInt] = 0;
for(w = 0; w < count; w++){
s[startInt] = 1;
min = -1;
for(z = 0; z < count; z++){
if(s[z]==0 && (min == -1 || d[z] < d[min])){
min = z;
}
}
s[min] = 1;
for(v = 0; ((s[v]==0) && (graph[u][v] != 0));v++){
if(d[min] + graph[min][v] < d[v]){
d[v] = d[min] + graph[min][v];
p[v] = min;
printf("P[%d] = %d\n",z,p[z]);
}
}
}
}
The program uses this function after compiling graph[t][f], where the entry in [t][f] is the distance from those cities.
After running dijkstra.. if I print d[endCity] I get 5000 (defined as my MAXINT) instead of the distance from the startCity to the endCity.
If I print p[endCity] down to p[0], they all have the same value: 0
Any help is greatly appreciated.