下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、一、實(shí)驗(yàn)?zāi)康?. 掌握棧的順序存儲結(jié)構(gòu)的存儲特點(diǎn)與操作特點(diǎn)。2. 掌握棧的存儲表示與基本操作的實(shí)現(xiàn)方法。3. 熟悉棧的基本應(yīng)用。4. 了解抽象數(shù)據(jù)類型的定義、表示與實(shí)現(xiàn)的含義。二、實(shí)驗(yàn)內(nèi)容編寫程序,進(jìn)行調(diào)試,寫出調(diào)試正確的源代碼,給出測試結(jié)果。在棧存儲結(jié)構(gòu)下,完成如下操作:迷宮求解(1)源代碼:1.h#define true 1#define false 0#define ok 1#define error 0#define infeasible -1#define overflow -2#define STACK_INIT_SIZE 30#define STACKINCREMENT 10ty
2、pedef int status;typedef structint i; int j;postype;typedef structint ord; postype seat; int di;selemtype;typedef structselemtype * base;selemtype *top;int stacksize;sqstack;sqstack s;typedef int mazetype55;mazetype maze;status initstack(sqstack &s);status push(sqstack &s,selemtype e); statu
3、s pop(sqstack &s,selemtype &e); status stackempty(sqstack s);status pass(postype curpos);postype nextpos (postype curpos,int di); status footprint(postype curpos); status markprint(postype curpos);#include<stdio.h>#include<stdlib.h>#include"1.h"status initstack(sqstack
4、&s)status push(sqstack &s,selemtype e)if(s.top-s.base>=s.stacksize) s.base=(selemtype s.base=(selemtype *)malloc(STACK_INIT_SIZE*sizeof(selemtype); if(!s.base) exit(overflow); s.top=s.base; s.stacksize=STACK_INIT_SIZE; return ok;*)realloc(s.base,(STACK_INIT_SIZE+STACKINCREMENT)*sizeof(sel
5、emtype);status pop(sqstack &s,selemtype &e)if(s.top=s.base) return error; s.top-; e=*s.top; return ok; if(!s.base) exit(overflow); s.top=s.base+s.stacksize; s.stacksize+=STACKINCREMENT; *s.top=e; s.top+; return ok;status stackempty(sqstack s)if(s.top=s.base) return true;else return false;sta
6、tus pass(postype curpos)if(curpos.i<1|curpos.i>10)|(curpos.j<1|curpos.j>10) return false;if(mazecurpos.icurpos.j=0) return true;else return false;postype nextpos (postype curpos,int di)status mazepath (mazetype maze,postype start,postype end) switch(di) return curpos; case 1:curpos.j+;br
7、eak; case 2:curpos.i+;break; case 3:curpos.j-;break; case 4:curpos.i-;break;initstack(s); postype curpos=start;/設(shè)當(dāng)前位置為入口位置 selemtype e;int curstep=1;/探索第一步do if(pass(curpos)/當(dāng)前位置可以通過,既是未曾走過的通道塊 else /當(dāng)前位置不能通過 if(!stackempty(s) pop(s,e); while(e.di=4&&!stackempty(s) markprint(e.seat); footpri
8、nt(curpos);/留下足跡 /e=(curstep,curpos,1); e.ord=curstep; e.seat=curpos; e.di=1; push(s,e);/加入路徑 /if(curpos=end) if(curpos.i=end.i)&&(curpos.j=end.j) return true;/到達(dá)終點(diǎn) curpos=nextpos(curpos,1);/下一位置是當(dāng)前位置的東鄰 curstep+;/探索下一步 pop(s,e);/留下不能通過的標(biāo)記,并退回一步 if(e.di<4) e.di+; push(s,e);/換下一個(gè)方向探索 curpo
9、s=nextpos(e.seat,e.di);/設(shè)定當(dāng)前位置是新方向上的相鄰塊status footprint(postype curpos)status markprint(postype curpos)void main() int i,j;postype start; postype end; start.i=1; mazecurpos.icurpos.j=3; return ok; mazecurpos.icurpos.j=2; return ok; while(!stackempty(s); return false;start.j=1; end.i=3; end.j=3; printf("請輸入迷宮內(nèi)容:n"); for(i=0;i<5;i+) for(j=0;j<5;j+) scanf("%d",&mazeij); if( mazepath(maze,start,end) for(i=0;i<5;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度建筑行業(yè)借款合同憑據(jù)規(guī)范模板
- 2025年度高性能復(fù)合材料研發(fā)與應(yīng)用合同-@-1
- 2025年度加氣磚研發(fā)項(xiàng)目采購合同范本
- 2025年合同稅率變更通知與執(zhí)行協(xié)議范本
- 2025年果蔬飲品品牌授權(quán)與采購合作協(xié)議
- 中國偏轉(zhuǎn)線圈行業(yè)市場深度分析及行業(yè)發(fā)展趨勢報(bào)告
- 智慧畜牧設(shè)備新建項(xiàng)目可行性研究報(bào)告建議書申請格式范文
- 2025年中國白乳膠行業(yè)競爭格局分析及投資戰(zhàn)略咨詢報(bào)告
- 2025年度新型城鎮(zhèn)化混凝土工程勞務(wù)分包合同模板
- 2025年中國碳碳復(fù)合材料行業(yè)市場發(fā)展現(xiàn)狀及投資規(guī)劃建議報(bào)告
- GB/T 707-1988熱軋槽鋼尺寸、外形、重量及允許偏差
- 浮力及浮力的應(yīng)用
- 公司培訓(xùn)員工職務(wù)犯罪預(yù)防講座之職務(wù)侵占
- 化學(xué)選修4《化學(xué)反應(yīng)原理》(人教版)全部完整PP課件
- 建筑公司工程財(cái)務(wù)報(bào)銷制度(精選7篇)
- 工程設(shè)計(jì)方案定案表
- 最新2022年減肥食品市場現(xiàn)狀與發(fā)展趨勢預(yù)測
- 第一章-天氣圖基本分析方法課件
- 暖氣管道安裝施工計(jì)劃
- 體育實(shí)習(xí)周記20篇
- 初二物理彈力知識要點(diǎn)及練習(xí)
評論
0/150
提交評論