#include<stdio.h>
#include<iostream>
using namespace std;
typedef int Status;
typedef char VerTexType;
typedef int SElemType;
typedef int ArcType;
#define MVNum 100
#define MAXSIZE 100 //栈空间
#define MAXQSIZE 100 //队列空间
#define OK 1
#define ERROR 0
bool visited[MVNum];
typedef struct //图的邻接矩阵法存储表示
{
VerTexType vexs[10][MVNum];
ArcType arcs[MVNum][MVNum];
int vexnum,arcnum;
}AMGraph;
typedef struct
{
ArcType *base; //初始化的动态分配存储空间
int front; //头指针,若队列不空,指向队头元素
int rear; //尾指针,若队列不空,指向队尾元素的下一个位置
}sqQueue;
void InitQueue(sqQueue &Q) //构造一个空队列Q
{
Q.base = new ArcType[MAXQSIZE];
if(!Q.base)
exit(1);
Q.front = Q.rear = 0;
}
void EnQueue(sqQueue &Q, ArcType e)//插入元素e为Q的新的队尾元素
{
if((Q.rear + 1) % MAXQSIZE == Q.front)
return;
Q.base[Q.rear] = e;
Q.rear = (Q.rear + 1) <
数据结构之DFS和BFS算法
最新推荐文章于 2024-04-24 17:48:12 发布
![](https://img-home.csdnimg.cn/images/20240709112858.png)