資源描述:
《源程序(帶注釋)》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、源程序(帶注釋)#include"stdio.h"#include"stdlib.h"#include"string.h"#defineMAX3/*車庫容量*/#defineprice0.05/*每車每分鐘費(fèi)用*/typedefstructtime{inthour;intmin;}Time;/*時(shí)間結(jié)點(diǎn)*/typedefstructnode{charnum[10];Timereach;Timeleave;}CarNode;/*車輛信息結(jié)點(diǎn)*/typedefstructNODE{CarNode*stack[MAX+1];inttop;}SeqStackC
2、ar;/*模擬車站*/typedefstructcar{CarNode*data;structcar*next;}QueueNode;typedefstructNode{QueueNode*head;QueueNode*rear;}LinkQueueCar;/*模擬通道*/voidInitStack(SeqStackCar*);/*初始化棧*/intInitQueue(LinkQueueCar*);/*初始化便道*/intArrival(SeqStackCar*,LinkQueueCar*);/*車輛到達(dá)*/voidLeave(SeqStackCar*
3、,SeqStackCar*,LinkQueueCar*);/*車輛離開*/voidList(SeqStackCar,LinkQueueCar);/*顯示存車信息*/voidmain(){SeqStackCarEnter,Temp;LinkQueueCarWait;intch;InitStack(&Enter);/*初始化車站*/InitStack(&Temp);/*初始化讓路的臨時(shí)棧*/InitQueue(&Wait);/*初始化通道*/while(1){printf("***************************************")
4、;printf("1.thecararrive");printf("t2.thecarleave");printf("3.theschedule");printf("tt4.out");printf("***************************************");while(1){scanf("%d",&ch);if(ch>=1&&ch<=4)break;elseprintf("pleasechoose:1
5、2
6、3
7、4.");}switch(ch){case1:Arrival(&Enter,&Wa
8、it);break;/*車輛到達(dá)*/case2:Leave(&Enter,&Temp,&Wait);break;/*車輛離開*/case3:List(Enter,Wait);break;/*列表打印信息*/case4:exit(0);/*退出主程序*/default:break;}}}voidInitStack(SeqStackCar*s)/*初始化棧*/{inti;s->top=0;for(i=0;i<=MAX;i++)s->stack[s->top]=NULL;}intInitQueue(LinkQueueCar*Q)/*初始化便道*/{Q->he
9、ad->next=NULL;Q->rear=Q->head;return(1);}voidPRINT(CarNode*p)/*打印出棧車的信息*/{introom;intA1,A2,B1,B2;printf("pleaseinputthedeparttime:");scanf("%d:%d",&(p->leave.hour),&(p->leave.min));printf("thenumberofthecar:");puts(p->num);printf("thetimethecararrive:%d:%d",p->reach.hour,p
10、->reach.min);printf("thedeparttime:%d:%d",p->leave.hour,p->leave.min);A1=p->reach.hour;A2=p->reach.min;B1=p->leave.hour;B2=p->leave.min;printf("thefee:%2.1fyuan",((B1-A1)*60+(B2-A2))*price);free(p);}intArrival(SeqStackCar*Enter,LinkQueueCar*W)/*車輛到達(dá)*/{CarNode*p;QueueNode*t;p=(
11、CarNode*)malloc(sizeof(CarNode));flushall();pri