dijkstra's algorithm

i have a small catch in following code.

/* to implement dijkstra's algorithm in c*/
2
3 #define MAX_NODES 1024 //maximum num of nodes
4 #define INFINITY 1000000000 //a number larger than every maximum path
5
6 int n,dist[MAX_NODES][MAX_NODES] ;
7 //dist[i][j] is the distance from i to j
8
9 //shortest path function
10 //path[] the path being worked on
11 void shortest_path(int s,int t,int path[])
12 {
13 struct state
14 { int predecessor; //previous node
15 int length; //length from source to this node
16 enum {permanent,tentative} label //label state
17 } state[MAX_NODES];
18
19 int l,k,min;
20
21 struct state * ptr;
22
23 for(p=&state[0];p<&state[n];p++) /*initial state */
24 {
25 p -> predecessor = -1;
26 p -> length = INFINITY;
27 p -> label = tentative;
28 }
29
30 state[t].length = 0;state[t].label=permanent;
31 k = t; // k is the initial working node
32
33 do //is the better path from k?
34 {
35
36 for(l=0;l<n;l++) //this graph has n nodes
37 if(dist[k][l] != 0 && state[l].label == tentative)
38 if(state[k].length+dist[k][l] < state[l].length)
{state[l].predecessor = k;
state[l].length = state[k].length + dist[k][l];
}
}
}

//to find the tentatively labeled node with the smallest label

k=0;
min = INFINITY;
for(l=0;l<n;l++)
if(state[l].label == tentative && state[l].length < min)



i have a problem in
this can u solve it

i
Last edited on
any reason why that cin.ignore() is in comments (line 61) ?
by the way, use [code] tags (<> icon) to post code
i just was trying to see if a newline char was tampering with my output so i used cin.ignore but it was not the case.therfore it was commented.
Last edited on
thanks cin.clear() has solved my problem
now how do i add a predefined dictionary to my program
and add words to it and lookup that dictionary using the modified code in the first post
Topic archived. No new replies allowed.