关于Queue.h以及Queue.cpp的原码请参考上一篇文章。
https://blog.youkuaiyun.com/weixin_41594045/article/details/90898792
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "Queue.h"
using namespace std;
typedef int ElemType;
typedef struct eNode{
int adjVex; //任意顶点u相邻接的顶点
ElemType w; //边的权值
struct eNode* nextArc; //指向下一个边结点
}eNode;
typedef struct{
int n; //图的当前顶点数
int e; //图的当前边数
eNode **a; //指向一维指针数组
}lGraph;
int Init(lGraph *lg,int nSize){
//初始化函数
int i;
lg->n = nSize;
lg->e = 0;
lg->a = (eNode **)malloc(sizeof(eNode*)*nSize);
if(!lg->a){
return 0;
}
else{
for(i=0;i<nSize;i++){
lg->a[i] = NULL;
}
}
}
int Exist(lGraph *lg,int u,int v){
//检查边是否存在的函数
eNode *p;
if(u<0||u<0||u>lg->n-1||v>lg->n-1||u==v)
return 0;
p = lg->a[u];
while(p&&p->adjVex!=v)
p = p->nextArc;
if(!p){
cout<<"Not Exist!"<<endl<<endl