#include<stdio.h>
#include<stdlib.h>
#define M 10 //自己规定为10*10的迷宫
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
int findway(int);
int NextStep(int *, int *, int );
typedef struct
{
int x, y; //坐标
int dir; //方向
}ElemType;
typedef struct StackNode//构造栈
{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
int InitStack(SqStack *S)//初始化栈
{
S->base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!S->base)
{
printf("memory allocation failed,goodbye");
exit(1);
}
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}
int Push(SqStack *S,ElemType e)//进栈操作
{
if(S->top-S->base>=S->stacksize)
{
S->base = (ElemType *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(ElemType));
if (!S->base)
{
printf("memory allocation failed,goodbye");
exit(1);
}
S->top = S->base+S->stacksize;
S->stacksize += STACKINCREMENT;
}
*S->top++=e;
return OK;
}
int Pop(SqStack *S,ElemType *e)//出栈操作
{
if(S->top==S->base)
{
return ERROR;
}
*e=*--S->top;
//printf("%d\n",e);
return OK;
}
int StackEmpty(SqStack *S)//判断栈是否为空
{
if(S->top==S->base)
return OK;
else
return ERROR;
}
void Input(char b[M][M])//输入时候请注意把一圈都输入为墙即'#'
{
int i, j;
printf("请输入迷宫形状:\n");
for (i = 0; i < M; i++)
{
for (j = 0; j < M; j++)
{
scanf("%c",&b[i][j]);
}
getchar();//吃掉内存中的残留换行符号
}
}