用栈的方法设计迷宫求解(c语言)。。限时

来源:百度知道 编辑:UC知道 时间:2024/05/05 19:40:34
题目:可以输入一个任意大小的迷宫数据,用非递归的方法求出一条走出迷宫的路径,并将路径输出;

最好有注释、储结构、基本算法(可以使用程序流程图)、源程序、测试数据和结果、算法的时间复杂度、另外可以提出算法的改进方法;

周四内有效
在vc下运行的

原来做过,以下为源代码和部分注释,可以运行
#include<stdio.h>
#include<stdlib.h>
#define M 15
#define N 15
struct mark //定义迷宫内点的坐标类型
{
int x;
int y;
};

struct Element //"恋"栈元素,嘿嘿。。
{
int x,y; //x行,y列
int d; //d下一步的方向
};

typedef struct LStack //链栈
{
Element elem;
struct LStack *next;
}*PLStack;

/*************栈函数****************/

int InitStack(PLStack &S)//构造空栈
{
S=NULL;
return 1;
}

int StackEmpty(PLStack S)//判断栈是否为空
{
if(S==NULL)
return 1;
else
return 0;
}

int Push(PLStack &S, Element e)//压入新数据元素
{
PLStack p;
p=(PLStack)malloc(sizeof(LStack));
p->elem=e;
p->next=S;
S=p;
return 1;
}

int Pop(PLStack &S,Element &e) //栈顶元素出栈
{
PLStack p;
if(!StackEmpty(S))
{
e=S-&g