#include <stdio.h>
#include<stdlib.h>
#define M 10
#define N 10
#define STACK_INIT_SIZE 100
#define STACK_INC 10
int flag=0;
typedef struct{
int x;
int y;
}Position;
typedef struct{
Position pos;
int id;
int dir;
}ElemType;
typedef struct{
ElemType *base;
ElemType *top;
int StackSize;
}SqStack;
void InitStack(SqStack &S){
S.base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType));
S.top=S.base;
S.StackSize=STACK_INIT_SIZE;
}
void push(SqStack &S,ElemType e){
if(S.top-S.base>=S.StackSize){
S.base=(ElemType *)realloc(S.base,(STACK_INIT_SIZE+STACK_INC)*sizeof(ElemType));
S.top=S.base+S.StackSize;
S.StackSize+=STACK_INC;
}
*S.top=e;
S.top++;
}
void pop(SqStack &S,ElemType &e){
S.top--;
e.dir=(*(S.top)).dir;
e.id=(*(S.top)).id;
e.pos.x=(*(S.top)).pos.x;
e.pos.y=(*(S.top)).pos.y;
}
int StackEmpty(SqStack S){
if(S.base==S.top)return 1;
return 0;
}
void iniarr(int (*p)[N]){
int i,j;
关于迷宫问题 利用栈实现
最新推荐文章于 2023-11-22 23:21:08 发布