单源最短路径问题-具有负边值的图

时间:2017-07-30 12:07:05   收藏:0   阅读:349

借助队列处理

void Unweighted(Table T) {
    Queue Q;
    Vertext V, W;
    Q = CreateQueue(NumVertex);
    MakeEmpty(Q);
    Enqueue(S, Q);

    while (!IsEmpty(Q)) {
        V = Dequeue(Q);
        T[V].Know = True;

        for each W adjacent to V
            if (T[V].Dist + Cvw < T[W].Dist) {
                T[W].Dist = T[V].Dist + Cvw;
                T[W].Path = V;
                if (W is not in Q)
                    Enqueue(W, Q);
            }
    }

    DisPoseQueue(Q);
}

 

原文:http://www.cnblogs.com/m2492565210/p/7258651.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!