#include<stdio.h>
#include<stdlib.h>
#define ERROR 0
#define OK 1
#define Overflow 2
#define Underflow 3
#define NotPresent 4
#define Duplicate 5
typedef int ElemType;
typedef struct
{
ElemType **a; //邻接矩阵
int n; //图的当前顶点数
int e; //图的当前边数
ElemType noEdge; //两顶点间无边时的值
}mGraph;
typedef int Status;
Status Init (mGraph *mg,int nSize,ElemType noEdgeValue)
{
int i,j;
mg->n=nSize; //初始化顶点数
mg->e=0; //初始时没有边
mg->noEdge=noEdgeValue; //初始化没有边时的取值
mg->a=(ElemType**)malloc(nSize*sizeof(ElemType*)); //生成长度为n的一维指针数组
if(!mg->a)
return ERROR;
for(i=0;i<mg->n;i++) //动态生成二维数组
{
mg->a [i]=(ElemType*)malloc(nSize*sizeof(ElemType*));
for(j=0;j<mg->
(C语言、数据结构)邻接矩阵的初始化、边的插入和输出,以及邻接矩阵的撤销和边的搜索
最新推荐文章于 2025-03-30 10:39:06 发布