数据结构 严蔚敏 C语言版 迷宫
status mazePath(seqStack *S, posType start, posType end)
{
posType curPos; //current positon
int curStep; //the ordinary number
sElemType e;
curPos = start;
curStep = 1;
do
{
if(pass(curPos)) //the current position is "accessed"
{
footPrint(curPos);
e.ord = curStep;
e.seat = curPos;
e.di = 1;
push(S, e);
if(curPos.xPos == end.xPos && curPos.yPos == end.yPos)
{
return OK; //arrive at the final
}
curPos = nextPos(curPos, 1);
curStep++;
}//end of if(pass(curPos))
else //the current position is not "accessed"
{
if(!stackEmpty(*S)) //the stack is not empty
{
pop(S,&e);
while(e.di == 4 && !stackEmpty(*S))
{
markPrint(e.seat); //the current position must be marked by '#'
pop(S,&e);
}//end while
if(e.di < 4)
{
e.di++;
push(S,e);
curPos = nextPos(e.seat, e.di);
}
}//end of if(!stackEmpty(*S))
}//end of else
}while(!stackEmpty(*S));
}
1