迷宫求解数据结构C语言版.doc
- Epiphany个人认证 |
- 2021-01-21 发布|
- 22.5 KB|
- 6页
PAGE / NUMPAGES
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct{ int r; int c;
}PosType;//通道块坐标
typedef struct { int ord;//通道块在路径上的序号 PosType seat;//通道块的坐标位置 int di;//下一个探索的方向
}SelemType;
typedef struct { int r; int c; char adr[10][10];
}MazeType;//迷宫行列,内容
typedef struct { SelemType * base; SelemType * top; int stacksize;
}SqStack;
void InitStack(SqStack &S)
{ S.base=(SelemType*)malloc(STACK_INIT_SIZE * sizeof(SelemType)); if(!S.base) exit(0); S.top=S.base; S.stacksize=STACK_INIT_SIZE;
}
void Push(SqStack &S,SelemType &e)
{ if((S.top-S.base)>=S.stacksize) { S.base=(SelemType*)realloc(S.base,(S.stacksize+STACKINCREMENT)* sizeof(SelemType)); if(!S.base) exit(0); S.top=S.base+S.sta