基于c語(yǔ)言的廣度優(yōu)先搜索

基于c語(yǔ)言的廣度優(yōu)先搜索

ID:28020488

大?。?41.56 KB

頁(yè)數(shù):9頁(yè)

時(shí)間:2018-12-07

基于c語(yǔ)言的廣度優(yōu)先搜索_第1頁(yè)
基于c語(yǔ)言的廣度優(yōu)先搜索_第2頁(yè)
基于c語(yǔ)言的廣度優(yōu)先搜索_第3頁(yè)
基于c語(yǔ)言的廣度優(yōu)先搜索_第4頁(yè)
基于c語(yǔ)言的廣度優(yōu)先搜索_第5頁(yè)
資源描述:

《基于c語(yǔ)言的廣度優(yōu)先搜索》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)

1、基于C語(yǔ)言的廣度優(yōu)先搜素算法的實(shí)現(xiàn)1.算法說(shuō)明廣度優(yōu)先搜索使用隊(duì)列(queue)來(lái)實(shí)現(xiàn),整個(gè)過(guò)程也可以看做一個(gè)倒立的樹(shù)形:(1)把根節(jié)點(diǎn)放到隊(duì)列的末尾。(2)每次從隊(duì)列的失部取出一個(gè)元素,查看這個(gè)元素所有的下一級(jí)元素,把它們放到隊(duì)列的末尾。并把這個(gè)元素記為它下一級(jí)元素的前驅(qū)。(3)找到所要找的元素吋結(jié)束程序。(4)如果遍歷整個(gè)樹(shù)還沒(méi)有找到,結(jié)束程序。本次算法的應(yīng)用中,我用這個(gè)隊(duì)列來(lái)保存最短路徑。首先我定義隊(duì)列為“真進(jìn)假出”,所謂“真進(jìn)”就是當(dāng)添加一個(gè)元素時(shí),把元素放置隊(duì)尾,然后rear++,而“假出”就是當(dāng)刪除一個(gè)元素吋,并沒(méi)有真的刪除隊(duì)首

2、元素,只是front++。通過(guò)比較搜索所得的所有可行路徑的長(zhǎng)度,這樣我們就可以從隊(duì)列屮獲取一條最短路徑!1.代碼及結(jié)果^includeftdefineNtypcdcfstruct{intx;inty;}Node;/*雙?親X的?序6號(hào)?*//*雙?親X的?序d號(hào)?*//*孩C子哩?的?坐?標(biāo)括?//*隊(duì)6元a素?類無(wú)?型i*/typcdcfstruct{intparent:intchild;Nodechi1dpos:}QType;intMaze[N][N]={1111111111111111111intvisitcd[N]

3、[N]={1,11111111,1,1,1,1,1,1,1,1,1,1,1,1,10,0,0,1,0,0,0,1,1,0,0,1,0,00,0,1,0,0,0,0,1,0,0,0,0,1,10,0,0,0,0,0,1,0,0,1,0,0,0,11,0,1,0,0,0,0,0,0,0,0,1,0,00,0,0,0,1,0,0,0,0,1,0,0,0,01,0,0,0,0,1,1,0,1,0,0,1,0,11,0,0,1,0,0,0,1,0,1,0,0,0,00,0,1,0,1,0,1,0,1,0,0,0,1,11,0,0,0,0,0,1,0,

4、0,0,1,0,0,00,0,0,1,0,0,0,0,1,0,0,1,1,01,1,1,0,1,0,0,1,0,1,0,0,0,10,0,1,0,0,0,1,0,0,1,0,0,0,00,1,1,1,1,1,0,0,0,1,0,0,1,01,0,0,0,0,0,1,0,0,1,0,0,0,10,0,0,1,0,0,0,0,1,0,0,0,0,01,0,0,1,0,1,0,0,1,0,0,1,0,00,0,0,1,0,0,0,1,0,0,1,0,0,01,0,0,0,1,0,0,0,1,0,0,0,1,01,1,1,1,1,1,1,1,1,1

5、,1,1,1,11,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0,0,0,1,1,0,0,1,0,00,0,1,0,0,0,0,1,0,0,0,0,1,10,0,0,0,0,0,1,0,0,1,0,0,0,11,0,1,0,0,0,0,0,0,0,0,1,0,00,0,0,0,1,0,0,0,0,1,0,0,0,01,0,0,0,0,1,1,0,1,0,0,1,0,11,0,0,1,0,0,0,1,0,1,0,0,0,00,0,1,0,1,0,1,0,1,0,0,0,1,11,1,1,1,1,0,0,0,1,1,1

6、,0,0,0,1,0,1,0,0,1,0,0,0,0,1,1,0,0,1,1,0,1,0,0,1,0,0,0,1,1,1,0,0,0,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,0,0,0,1,0,1,0,1,1,1,0,1,1,1,0,1,0,0,1,1,0,0,0,1,0,0,1,0,1,1,1,1,1,1}0,0,0,1,11,0,0,0,10,1,0,0,10,0,0,0,11,0,0,1,10,1,0,0,10,0,0,1,11,0,0,0,11,1,0,0,0,0,0,1,0,0,0,

7、1,0,0,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,0,0,1,0,0,0,0,1,1,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,0,1,0

8、,0,1,0,0,1,0,0,0,1,0,0,1,1,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,0,0,1,0,0,

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動(dòng)畫(huà)的文件,查看預(yù)覽時(shí)可能會(huì)顯示錯(cuò)亂或異常,文件下載后無(wú)此問(wèn)題,請(qǐng)放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫(kù)負(fù)責(zé)整理代發(fā)布。如果您對(duì)本文檔版權(quán)有爭(zhēng)議請(qǐng)及時(shí)聯(lián)系客服。
3. 下載前請(qǐng)仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進(jìn)行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
4. 下載文檔時(shí)可能由于網(wǎng)絡(luò)波動(dòng)等原因無(wú)法下載或下載錯(cuò)誤,付費(fèi)完成后未能成功下載的用戶請(qǐng)聯(lián)系客服處理。