1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

dijkstra's shortest path in c

Discussion in 'C' started by dmm83, May 26, 2015.

  1. dmm83

    dmm83 New Member

    Joined:
    May 26, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Here is my code to implement dijkstra's algorithm in shortest path to show vertices and that are known with shortest path. This is stressing me out. The output is 5 0 1 2 3 4 6. From it any help will be happy
    Code:
    void d_run(Table T, Graph G){
        Vertex V, W;
        V = 0;
        W = 0;
        for (int i = 0; i < T.V; i++){
            int newdist = 0;
            int current = 20000;
            for (int j = 0; j < T.V; j++)
            {
                newdist = T.entries[j].dist;
                if (newdist < current && (T.entries[j].known == false)){
                    current = newdist;
                    V = j;
                }
            }
            if (V == notavertex){
                break;
            }
            T.entries[V].known = true;
            // pointer to beginning of list of edges need 
            // to work out how to read them
            T.entries[V].header = G.edges[i];
            //T.entries[V].header = T.entries[W].header;
            //for (){
                if (!T.entries[W].known){
                    if (T.entries[V].dist < T.entries[W].dist){
                        T.entries[W].dist = T.entries[V].dist;
                        T.entries[W].path = V;
                    }
                    //return T.entries;
                }
                printf("%d ", V);
            //}
        }
        printf("\n");
    }
     

Share This Page