第3章 栈和队列概论.ppt

Status MazePath(maze, start, end) { //若迷宫中存在一条从入口start到出口end的通道,则求出这样的一条通路 InitStack(S); curpos = start; curstep = 1; do { if (pass(curpos)) { //当前位置可以通过 Mark(maze,curpos); //留下记号 e = (curstep,curpos,1); push(S,e); //加入路径 if (curpos==end) return true; //到达出口 curpos = NextPos(curpos,1) ;//下一个位置 curstep++; } else {//当前位置不能通过 if (!StackEmpty(S)){ pop(S,e); //退回一步 while(e.di==4 ! !StackEmpty(S)) {//当前位置是死胡同 Markdead(maze,e.seat);pop(S,e); //留下记号,沿来路返回 } if

文档评论(0)

1亿VIP精品文档

相关文档