#include #include #include "book.h" #include "grlist.h" // Floyd's all-pairs shortest paths algorithm void Floyd(Graph* G) { int D[G->n()][G->n()]; // Store distances for (int i=0; in(); i++) // Initialize D with weights for (int j=0; jn(); j++) D[i][j] = G->weight(i, j); for (int k=0; kn(); k++) // Compute all k paths for (int i=0; in(); i++) for (int j=0; jn(); j++) if (D[i][j] > (D[i][k] + D[k][j])) D[i][j] = D[i][k] + D[k][j]; } // Test Depth First Search: // Version for Adjancency Matrix representation main(int argc, char** argv) { Graph* G; FILE *fid; if (argc != 2) { cout << "Usage: grdfsm \n"; exit(-1); } if ((fid = fopen(argv[1], "rt")) == NULL) { cout << "Unable to open file |" << argv[1] << "|\n"; exit(-1); } G = createGraph(fid); if (G == NULL) { cout << "Unable to create graph\n"; exit(-1); } Floyd(G); return 0; }