资源描述:
《源程序(带注释)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、源程序(带注释)#include"stdio.h"#include"stdlib.h"#include"string.h"#defineMAX3/*车库容量*/#defineprice0.05/*每车每分钟费用*/typedefstructtime{inthour;intmin;}Time;/*时间结点*/typedefstructnode{charnum[10];Timereach;Timeleave;}CarNode;/*车辆信息结点*/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*);/*车辆到达*/voidLeave(SeqStackCar*
3、,SeqStackCar*,LinkQueueCar*);/*车辆离开*/voidList(SeqStackCar,LinkQueueCar);/*显示存车信息*/voidmain(){SeqStackCarEnter,Temp;LinkQueueCarWait;intch;InitStack(&Enter);/*初始化车站*/InitStack(&Temp);/*初始化让路的临时栈*/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;/*车辆到达*/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)/*车辆到达*/{CarNode*p;QueueNode*t;p=(
11、CarNode*)malloc(sizeof(CarNode));flushall();pri