C语言邻接矩阵图的创建与打印代码修复
#include<stdio.h>\n#include<string.h>\n#define maxv 10\n#define inf 32767\ntypedef char infotype;\ntypedef struct {\n int no;\n infotype info;\n} vertextype;\ntypedef struct {\n int edges[maxv][maxv];\n vertextype vexs[maxv];\n int n;\n} matgraph;\n\nvoid creatematgraph(matgraph *T, int n) {\n char ch[10];\n int k = 0, i = 0;\n int j = 0, r;\n while (k < n) {\n fgets(ch, sizeof(ch), stdin);\n T->vexs[k].no = i;\n T->vexs[k].info = ch[0];\n k++;\n if (k >= n) break;\n }\n while (i < n) {\n j = 0;\n while (j < n) {\n printf("Is the edge [%d][%d] exist?\n", i, j );\n scanf("%d", &r);\n T->edges[i][j] = r;\n j++;\n }\n i++;\n }\n}\n\nvoid printgraph(matgraph *T, int n) {\n int k = 0;\n while (k < n) {\n printf("No%d: %c\t", T->vexs[k].no, T->vexs[k].info);\n k++;\n }\n printf("\n");\n int i = 0, j = 0;\n while (i < n) {\n j = 0;\n while (j < n) {\n printf("%d\t", T->edges[i][j]);\n j++;\n }\n printf("\n");\n i++;\n }\n}\n\nint main() {\n matgraph L;\n int n = 5;\n creatematgraph(&L, n);\n printgraph(&L, n);\n return 0;\n}
原文地址: https://www.cveoy.top/t/topic/qfYN 著作权归作者所有。请勿转载和采集!