史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2011-10-11, 09:19 PM   #1
sdds4747
註冊會員
榮譽勳章

勳章總數
UID - 348987
在線等級: 級別:0 | 在線時長:1小時 | 升級還需:4小時
註冊日期: 2011-10-02
文章: 2
精華: 0
現金: 2 金幣
資產: 2 金幣
預設 疑問 - 迷宮

這一個程式它是怎麼執行的阿
他的每一行 做啥


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”);
sdds4747 目前離線  
送花文章: 0, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用

相似的主題
主題 主題作者 討論區 回覆 最後發表
程式 - 關於”迷宮”的程式碼 ber751 程式語言討論區 0 2007-11-29 10:12 PM


所有時間均為台北時間。現在的時間是 02:06 PM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1