




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、數(shù)據(jù)結(jié)構(gòu)實(shí)驗(yàn)姓名:學(xué)號:專業(yè):班級:實(shí)驗(yàn)二 停車場管理程序【實(shí)驗(yàn)學(xué)時(shí)】5學(xué)時(shí)【實(shí)驗(yàn)?zāi)康摹空莆諚5暮筮M(jìn)先出特點(diǎn)【問題描述】設(shè)停車場內(nèi)只有一個(gè)可停放輛汽車的狹長通道,且只有一個(gè)大門可供汽車進(jìn)出。汽車在停車場內(nèi)按車輛到達(dá)時(shí)間的先后順序,依次由北向南排列,若停車場內(nèi)已停滿輛汽車,則后來的汽車只能在門外的便道上等侯,一旦有車開走,則排在便道上的第一輛車即可開入;當(dāng)停車場內(nèi)某輛車要離開時(shí),在它之后開入的車輛必須先退出車場為它讓路,待該輛車開出大門外,其它車輛再按原次序進(jìn)入車場,每輛停放在車場的車在它離開停車場時(shí)必須按它停留的時(shí)間長短交納費(fèi)用。試為停車場編制按上述要求進(jìn)行管理的模擬程序。【實(shí)驗(yàn)程序】#inc
2、lude<stdio.h>#include<stdlib.h>#include<malloc.h>#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define INFEASIBLE -1#define OVERFLOW -2#define SIZE 3/停車場位置數(shù)typedef int Status;/模擬停車場typedef struct Car1/車 int number;/車號 int ar_time;/到達(dá)時(shí)間CarNode;typedef struct/停車場 CarNode *b
3、ase;/停車場的堆棧底 CarNode *top;/停車場的堆棧頂 int stacksize;Park;/模擬便道typedef struct Car2/車 int number;/車號 int ar_time;/到達(dá)時(shí)間 struct Car2 *next;*CarPtr;typedef struct/便道 CarPtr front;/便道的隊(duì)列的對頭 CarPtr rear;/便道的隊(duì)列的隊(duì)尾 int length;Shortcut;Status InitStack(Park &P) P.base=(CarNode*)malloc(SIZE*sizeof(Car1); if(!
4、P.base) exit(OVERFLOW); P.top=P.base; P.stacksize=0; return OK;Status Push(Park &P,CarNode e)/進(jìn)入停車場 *P.top+=e; +P.stacksize; return OK;Status Pop(Park &P,CarNode &e)/離開停車場 if(P.top=P.base) printf("停車場為空。"); else e=*-P.top; -P.stacksize; return OK;Status InitQueue(Shortcut &
5、S) S.front=S.rear=(CarPtr)malloc(sizeof(Car2); if(!S.front|!S.rear) exit(OVERFLOW); S.front->next=NULL; S.length=0; return OK;Status EnQueue(Shortcut &S,int number,int ar_time)/進(jìn)入便道 CarPtr p; p=(CarPtr)malloc(sizeof(Car2); if(!p) exit(OVERFLOW); p->number=number; p->ar_time=ar_time; p-&
6、gt;next=NULL; S.rear->next=p; S.rear=p; +S.length; return OK;Status DeQueue(Shortcut &S,CarPtr &w)/離開便道 if(S.length = 0) printf("通道為空。"); else w = S.front->next; S.front->next=S.front->next->next; -S.length; return OK;Status Arrival(Park &P,Shortcut &S)/進(jìn)站車輛的
7、處理 int number,ar_time; printf("請輸入車牌號:"); scanf("%d",&number); printf("進(jìn)場的時(shí)刻:"); scanf("%d",&ar_time); if(P.stacksize<SIZE) CarNode c; c.number=number; c.ar_time=ar_time; Push(P,c); printf("該車應(yīng)停在第%d號車道。n",P.stacksize); else EnQueue(S,numbe
8、r,ar_time); printf("停車場已滿,請暫時(shí)停在便道的第%d個(gè)位置。n",S.length); return OK;Status Leave(Park &P,Park &P1,Shortcut &S)/離站車輛的處理 int number,le_time,flag=1,money,ar_time; printf("請輸入車牌號:"); scanf("%d",&number); printf("出場的時(shí)刻:"); scanf("%d",&le_
9、time); CarNode e,m; CarPtr w; while(P.stacksize) Pop(P,e); if(e.number=number) flag=0; money=(le_time-e.ar_time)*2; ar_time=e.ar_time; break; Push(P1,e); while(P1.stacksize) Pop(P1,e); Push(P,e); if (flag = 0) if(S.length!=0) DeQueue(S,w); m.ar_time=le_time; m.number=w->number; Push(P,m); free(w)
10、; printf("車牌號為%d的車已由便道進(jìn)入停車場",m.number); printf("停車費(fèi)為%d, 總占用車位數(shù)為%d,剩余車位數(shù)為%dn",money,P.stacksize,SIZE-P.stacksize); else printf("停車場不存在牌號為%d的車n", number); return OK;void main() int m=1; char flag; Park P,Q; Shortcut S; InitStack(P); InitStack(Q); InitQueue(S); while(m) pr
11、intf("n 停車場管理程序 n"); printf("=n"); printf("* A 汽車進(jìn)車場 *n"); printf("* D 汽車出車場 *n"); printf("* E 退出程序 *n"); printf("請選擇(A,D,E): "); scanf("%c",&flag); switch(flag) case 'A': case 'a': Arrival(P,S);break; /車進(jìn)入停車場 case 'D': case 'd': Leave(P,Q,S)
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中標(biāo)格式合同范本
- 省級課題申報(bào)書研究手段
- 買貓質(zhì)保合同范本
- 鳳爪貿(mào)易合同范本
- 烹飪課題申報(bào)書
- 2025生產(chǎn)設(shè)備大數(shù)據(jù)輕量化采集要求
- 單方面解約合同范本
- 產(chǎn)供銷合同范本
- 小學(xué)音樂類課題申報(bào)書
- 制作公司合同范本
- 《簡愛》課本劇劇本
- 社區(qū)獲得性肺炎臨床路徑
- 產(chǎn)品品質(zhì)檢驗(yàn)流程標(biāo)準(zhǔn)規(guī)范模板()
- DB12-595-2015醫(yī)院安全防范系統(tǒng)技術(shù)規(guī)范
- 五年級下冊英語課件-Unit 2 My favourite season B Let's learn 人教PEP版(共15張PPT)
- GB∕T 7260.40-2020 不間斷電源系統(tǒng) UPS 第4部分:環(huán)境 要求及報(bào)告
- 高邊坡施工危險(xiǎn)源辨識及分析
- 水廠項(xiàng)目基于BIM技術(shù)全生命周期解決方案-城市智慧水務(wù)講座課件
- 幼兒園繪本:《閃閃的紅星》 紅色故事
- 三年級學(xué)而思奧數(shù)講義.doc
- 產(chǎn)品承認(rèn)書客(精)
評論
0/150
提交評論