i
cludestdioh
i
cludemalloch
i
cludestdlibh
i
cludestri
gh
i
cludetimeh
defi
eOK
1
defi
eERROR0
defi
eNULL0
defi
eOVERFLOW2
defi
eSTACK_INIT_SIZE100
defi
eSTACKINCREMENT10
栈的顺序存储表示
typedefstruct
i
tx
列
i
ty
行
PosType坐标位置类型
typedefstructi
tordPosTypeseati
tdi
SElemType
通道块在路径上的序号通道块在迷宫中的坐标位置
从此通道块走向下一通道块的方向栈的元素类型
typedefstructSElemTypebaseSElemTypetopi
tstacksize
SqStack
当前已分配的存储空间,以元素为单位
基本操作i
tI
itStackSqStackS
SbaseSElemTypemallocSTACK_INIT_SIZEsizeofSElemTypeifSbaseexitOVERFLOWStopSbaseSstacksizeSTACK_INIT_SIZEretur
OK若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERRORi
tGetTopSqStackSSElemTypeeifStopSbaseretur
ERROReStop1
fretur
OK
i
tPushSqStackSSElemTypee插入元素e作为新的栈顶元素
ifStopSbaseSstacksize栈满,追加存储空间SbaseSElemTypereallocSbaseSstacksizeSTACKINCREMENTsizeofSElemType
ifSbaseexitOVERFLOWStopSbaseSstacksizeSstacksizeSTACKINCREMENTStoperetur
OK若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERRORi
tPopSqStackSSElemTypeeifStopSbaseretur
ERROReStopretur
OK
i
tStackEmptySqStackS
retur
StopSbase
迷宫程序
typedefstruct
i
tlie
列数
i
tha
g
行数
chara999999
MazeType
迷宫类型
随机生成迷宫i
tge
eratemazeMazeTypemaze
i
tijmazea002mazeamazeha
gmazelie3
设置外墙mazea0mazelie
fmazeamazeha
g0
forj1jmazeliej
mazea0jmazeamazeha
gj
fori1imazeha
gi
mazeai0mazeaimazelie
sra
du
sig
edtimeNULL
ra
d
fori1imazeha
gi
forj1jmazeliej
ifra
dRAND_MAX4mazeaij暗示出路
elsemazeaij
暗示无出路
retur
OK
i
tPassMazeTypemazePosTypecurpos判断当前位置可否通过
ifcurposx1curposxmazelieretur
ERRORifcurposy1curposymazeha
gretur
ERRORifmazeacurposycurposxretur
OK
elseretur
ERROR
i
tFootPri
tMazeTypemazePosTypecurpos留下足迹
mazeacurposycurposxretur
OK
i
tMarkPri
tMazeTypemazePosTypecurpos留下不能通过的标记
mazeacurposycurposxretur
OK
PosTypeNextPosPosTypecurposi
tdi
PosTypeposcurpos
switchdi
case1
右东
posx
break
返r