Floyd

#define MAXVEX 9;
#define INFINITY 65535;

typedef int Pathmatirx[MAXVEX][MAXVEX];
typedef int ShortPathTable[MAXVEX][MAXVEX];

void ShortesPath_Floyd(MGraph G, Pathmatirx *P, ShortPathTable *D){
    int v, w, k;
    for(v=0; v<G.numVertexes; v++){
        for (w=0; w<G.numVertexes; w++){
            (*D)[v][w] = G.matirx[v][w];
            (*P)[v][w] = w;
        }
    }

    for(k=0; k<G.numVertexes; k++){
        for (v=0; v<numVertexes; v++){
            for (w=0; w<numVertexes; w++){
                if ((*D)[v][w] > (*D)[v][k] + (*D)[k][w] ){
                    (*D)[v][w] = (*D)[v][k] + (*D)[k][w];
                    (*P)[v][w] = (*P)[v][k];
                }
            }
        }
    }
}
原文地址:https://www.cnblogs.com/Kingpenguin/p/10070345.html