#include <stdio.h> #include <stdlib.h> #include "graph.h"
int main() { Graph g; int i, j; int ver = 8; int v1, v2;
Edge e[] = {{0, 1},{0, 2}, {0, 5}, {0, 6}, {1, 2}, {2, 3}, {2, 4}, {3, 4}, {4, 5}, {4, 6}}; j = sizeof(e) / sizeof(e[0]);
g = graphinit(ver); if (g == NULL) { printf("init graph error\n"); exit(1); }
for (i = 0; i < j; i++) if (graphinserte(g, e[i]) < 0) { printf("insert error\n"); break; }
graphshow(g);
scanf("%d %d", &v1, &v2); if (graphpath(g, v1, v2)) { printf("\n%d-%d has path\n", v1, v2); } else { printf("%d-%d has no path\n", v1, v2); }
graphdestroy(g); return 0; }
|