code/BelmanFord.code
author lindenmannm
Tue, 22 Feb 2011 19:14:19 +0100
changeset 5 675024f99bf0
permissions -rw-r--r--
update xD
     1 DIST[s]=0;
     2 Z[s]=0;
     3 forall(v:V\{s}) {
     4     DIST[v]=infty;
     5     Z[v]=0;
     6 }
     7 U={s};
     8 while(!U.Empty) {
     9     Wähle und streiche Knoten u am Kopf von U;
    10     Z[u]=Z[u]+1;
    11     if Z[u]>n
    12         return "negativer Zyklus";
    13     forall(e=(u,v):E) {
    14         if(DIST[v]>DIST[u]+c(u,v)) {
    15             DIST[v]=DIST[u]+c(u,v);
    16             U=[U,{v}];
    17 }}}