|
该程序运行正常,但运行完毕后多了一个断错误,为什么?
[code:1]
/*无向网邻接矩阵*/
#include <stdio.h>
#define INT_MAX 32767
#define vnum 20
typedef struct graph
{
int vexs[vnum]; /*顶点信息*/
int arcs[vnum][vnum]; /*邻接矩阵*/
int vexnum, arcnum; /*顶点数,弧(边)数*/
} GraphTp;
GraphTp* CreateGraph (GraphTp *ga);
GraphTp* InitiateGraph (GraphTp *ga);
int main (void)
{
GraphTp *ga;
ga = CreateGraph(ga);
Print_Matrix(ga);
}
GraphTp* CreateGraph (GraphTp *ga)
{
int vex, arc, vexs, arcnum;
int i, j, k;
printf("请输入顶点个数:");
scanf("%d", &vex);
printf("请输入边数个数:");
scanf("%d", &arc);
ga -> vexnum = vex;
ga -> arcnum = arc;
for (i = 0; i < ga -> vexnum; i++)
{
printf("输入第%d个顶点信息:", i + 1);
scanf("%d", &vexs);
ga -> vexs[i] = vexs;
}
for (i = 0; i < ga -> vexnum; i++)
for (j = 0; j < ga -> vexnum; j++)
ga -> arcs[i][j] = INT_MAX;
for (k = 0; k < ga -> arcnum; k++)
{
printf("请输入第%d条边的起点编号,终点编号:", k + 1);
scanf("%d %d", &i, &j);
i--;
j--;
printf("输入该边的权值:");
scanf("%d", &arcnum);
ga -> arcs[i][j] = arcnum;
ga -> arcs[j][i] = arcnum;
}
return (ga);
}
int Print_Matrix (GraphTp *ga)
{
int i, j;
printf("邻接矩阵:\n");
printf("\t");
for (i = 0; i < ga -> vexnum; i++)
printf("%6d", ga -> vexs[i]);
printf("\n");
for (i = 0; i < ga -> vexnum; i++)
{
printf("%6d\t", ga -> vexs[i]);
for (j = 0; j < ga -> vexnum; j++)
printf("%6d", ga -> arcs[i][j]);
printf("\n");
}
}
[/code:1] |
|