![]() |
迷宮
這一個程式它是怎麼執行的阿
他的每一行 做啥 0 1 0 0 0 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 1 1 1 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 1 1 0 1 1 1 1 0 void path(void) {/* 輸出迷宮的一個路徑(如果有的話) */ int i, row, col, nextRow, nextCol, dir, found = FALSE; element position; mark[1][1] = 1; top = 0; stack[0].row = 1; stack[0].col = 1; stack[0].dir = 1; while(top > -1 && !found) { position = pop(); row = position.row; col = position.col; dir = position.dir; while (dir < 8 && !found) { /* 以dir的方向移動 */ nextRow = row + move[dir].vert; nextCol = col + move[dir].horiz; if (nextRow == EXIT_ROW && nextCol == EXIT_COL) found = true; elseif( !maze[nextRow][nextCol] && !mark[nextRow][nextCol]) { mark[nextRow][nextCol]=1; position.row = row; position.col = col; position.dir = ++dir; push(position); row = nextRow; col = nextCol; dir = 0; } else ++dir; } } if (found) { printf("The path is:\n”); printf(“row col\n”); for(i = 0; i <= top; i++) printf(“%2d%5d”,stack[i].row, stack[i].col); printf(“%2d%5d\n”,row,col); printf(“%2d%5d\n”,EXIT_ROW,EXIT_COL); } else printf(“The maze does not have a path\n”); |
所有時間均為台北時間。現在的時間是 01:39 PM。 |
Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.
『服務條款』
* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *