mGraph.cpp:
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include "Queue.h"
using namespace std;
typedef int ElemType;
typedef struct{
ElemType noEdge; //两顶点间没有边时的值
int e; //当前边数
int n; //当前顶点数
ElemType **a;
}mGraph; //邻接矩阵的结构体
ElemType Init(mGraph *mg,int nSize,int noEdgeValue){
//初始化函数
int i,j;
mg->noEdge = noEdgeValue;
mg->n = nSize;
mg->e = 0; //初始化时没有边
mg->a = (ElemType **)malloc(sizeof(ElemType *)*nSize); //生成长度为n的一位指针数组
if(!mg->a){
cout<<"Run out of Memory!"<<endl;
return 0;
}
for(i=0;i<mg->n;i++){
mg->a[i] = (ElemType *)malloc(sizeof(ElemType)*(mg->n));
for(j=0;j<mg->n;j++){
mg->a[i][j] = mg->noEdge;
}
mg->a[i][i] = 0;
}
return 0;
}
void Destroy(mGraph *mg){
//释放内存函数
int i;
for(i=0;i<mg->n;i++){
free(mg->a[i]);
}
free(mg->a);
}
ElemType Exist(mGraph *mg,int u,int v){
//查询是否有该边
if(u==v||mg->a[u-1][v-1]==mg->noEdge||u<1||v<1||u>mg->n||v>mg->n){
cout<<"Not Exist!"<<endl;
return 0;
};
cout<<"Exist!"<<endl;
return 0;
}
ElemType Insert(mGraph *mg,int u,int v,int w