#include "stdio.h"
//深度优先遍历算法
//求图中起点s到终点e的路径是否存在。图中的每个点至多有2个发出点。图以有向边(0,1)的形式给出. 图中不存在环。
//输入数据
//1 16(casenumber和边的数目)
//0 1 0 2 1 4 1 3 4 8 4 3 2 9 2 5 5 6 5 7 7 99 7 9 9 8 9 10 6 10 3 7 (16条边的数据)
#define MAX 100
typedef struct elem
{
int ent; //入栈的数据
int dir; //点的下一个查找方向,0为第一个查找方向,1为第二个,2,3依次类推
}elem;
//栈的定义
elem stack[MAX];
int top;
void initStack()
{
int i;
top = -1;
for(i=0; i<MAX; i++)
{
stack[i].ent=-1;
stack[i].dir=-1;
}
}
int isFull()
{
if(top==MAX-1)
{
return 1;
}
return 0;
}
int isEmpty()
{
if(top==-1)
{
return 1;
}
return 0;
}
int push(elem e)
{
if(isFull() == 1)
{
return 0;
}
top++;
stack[top]=e;
return 1;
}
int pop(elem *e)
{
if(isEmpty()==1)
{
return 0;
}
*e=stack[top];
top--;
return 1;
}
int getTop(elem * e)
{
if(isEmpty()==1)
{
return 0;
}
[深度优先遍历—栈实现]求图中两点是否连通
最新推荐文章于 2023-06-28 08:45:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)