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

借助队列处理

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

    while (!IsEmpty(Q)) {
        V = Dequeue(Q);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);
}

 

转载于:https://www.cnblogs.com/m2492565210/p/7258651.html

你可能感兴趣的:(单源最短路径问题-具有负边值的图)