棧和遞迴 解決迷宮問題

2021-08-04 03:47:15 字數 1502 閱讀 5331

走過的路設定為2,未走過的路設定0,牆設定為1;

**如下:
bool checkpath(const pos& cur)

bool getmazepath(pos& entry)

pos next = cur;

//上next._row -= 1;

if(checkpath(next))

next = cur;

//右next._col += 1;

if(checkpath(next))

next = cur;

//下next._row += 1;

if(checkpath(next))

next = cur;

//左next._col -= 1;

**如下:

//遞迴法

void getmazepathr(pos entry)

next = cur;

//右next._col += 1;

if(checkpath(next))

next = cur;

//下next._row += 1;

if(checkpath(next))

next = cur;

//左next._col -= 1;

**如下:
bool checkpath(const pos& cur, const pos& pre)

return

false;

}void getshortpathr(pos entry)//遞迴求最短路徑

next = cur;

//右next._col += 1;

if(checkpath(next,cur))

next = cur;

//下next._row += 1;

if(checkpath(next,cur))

next = cur;

//左next._col -= 1;

if(checkpath(next,cur))

}

迷宮問題 遞迴解決

建立人 wdl 建立時間 2021 3 21 描述 public class migong 左右全部置為1 for int i 0 i 8 i 設定擋板,1表示 map 3 1 1 map 3 2 1 map 1 2 1 map 2 2 1 輸出地圖 system.out.println 地圖的情況...

遞迴 解決迷宮問題

先用二維陣列模擬出 給部分 賦值1來說明是牆壁 紅色部分 public static void main string args 設定障礙 map 3 1 1 map 3 2 1 map 1 2 1 map 2 2 1 列印 for int i 0 i 10 i system.out.println...

解決迷宮問題, 棧和佇列

includeusing namespace std const int m 10,n 10 int mg m 1 n 1 const maxsize 200 struct qu maxsize int front 1,rear 1 隊首指標和隊尾指標 1 首先將 1,1 入隊 2 在佇列qu不為空...