汽车管理程序.doc_第1页
汽车管理程序.doc_第2页
汽车管理程序.doc_第3页
汽车管理程序.doc_第4页
汽车管理程序.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include#include#define N 2 /*停车场内最多的停车数目*/#define M 3 /* 候车场内做多的停车数目*/#define Price 2 /*每单位时间内停车费用*/typedef structint CarNoN; /*车牌号*/int CarTimeN; /*进场时间*/int top;SqStack; /*定义顺序栈类型*/typedef structint CarNoM;int front,rear;SqQueue;/*以下是顺序栈的基本算法*/SqStack* InitStack()SqStack *s;s=(SqStack *)malloc(sizeof(SqStack);s-top=-1;return s;int StackEmpty(SqStack *s)return (s-top=-1);int StackFull(SqStack *s)return (s-top=N-1);int Push(SqStack *s,int e1,int e2)if(s-top=N-1)return 0; /*栈已满无法插入*/elses-top+;s-CarNos-top=e1;s-CarTimes-top=e2;return 1; /*插入成功*/int pop(SqStack *s,int *e1,int *e2)if(s-topCarNos-top;*e2=s-CarTimes-top;s-top-;return 1; /*出栈成功*/void DispStack(SqStack *s)/*输出栈中元素*/int i;for(i=s-top;i-1;i-)printf(%d ,s-CarNoi); printf(n);/*以下是循环队列的基本算法*/SqQueue* InitQueue() SqQueue *q;q=(SqQueue *)malloc(sizeof(SqQueue);q-front=q-rear=0;return q;int QueueEmpty(SqQueue *q)return(q-front=q-rear);int QueueFull(SqQueue *q)/*判断循环队列是否为满,注意与顺序队列的区别*/return(q-rear+1)%M=q-front);int enQueue(SqQueue *q,int e)if(q-rear+1)%M=q-front)return 0;else q-rear=(q-rear+1)%M; q-CarNoq-rear=e; return 1;int deQueue(SqQueue *q,int *e)if(q-front=q-rear)return 0;elseq-front=(q-front+1)%M;*e=q-CarNoq-front; /*出队的对头元素到参数e中*/return 1;void DispQueue(SqQueue *q)/*输出队中元素*/int i;i=(q-front+1)%M;printf(%d ,q-CarNoi);while(q-rear-i+M)%M0)i=(i+1)%M;printf(%d ,q-CarNoi);printf(n);void main()int comm;/*每一种情况*/int no,time,e1,e2;/*no为车牌号,time为停车时间e2为停车时间*/int i,j;SqStack *St,*St1; /*st为停车场,St1为临时车场*/SqQueue *Qu; /*Qu为候车场*/St=InitStack(); St1=InitStack();Qu=InitQueue();doprintf(输入指令(1:到达 2:离开 3:停车场 4:候车场 0:退场): );scanf(%d%d%d,&comm,&no,&time);switch(comm) case 1: /* 汽车到达*/if(!StackFull(St) /*停车场不满*/Push(St,no,time);printf( 停车场位置:%dn,St-top+1);else /*停车场满*/if(!QueueFull(Qu) /*停车场满但候车场不满*/enQueue(Qu,no);printf(候车场位置:%dn,Qu-rear);elseprintf(候车场已满,不能停车!n); /*停车场满,候车场也满*/break;case 2: /*汽车离开*/for(i=-1;itop&St-CarNoi!=no;i+);if(iSt-top)printf(未找到该编号的汽车!n);elsefor(j=i;jtop;j+)pop(St,&e1,&e2);/凡是传值的我都给你变成了传址。Push(St1,e1,e2); /*汽车到临时栈St1*/pop(St,&e1,&e2);/*该汽车离开*/printf(%d汽车停车费用:%dn,no,(time-e2)*Price);while(!StackEmpty(St1)/*将临时栈内的汽车又到回停车场中*/pop(St1,&e1,&e2);Push(St,e1,e2);if(!QueueEmpty(Qu)/*队不空时,将队头进栈*/deQueue(Qu,&e1);Push(St,e1,time);/*以当前时间计费*/break;case 3: /*显示停车场情况*/if(!StackEmpty(St)printf( 停车场中的车辆:);DispStack(St);elseprintf(停车场中无车辆!n);break;case 4: /*显示候车场情况*/if(!QueueEmpty(Qu)printf(候车场中的车辆:);DispQueue(Qu);elseprintf(侯停场中无车辆!n);break;case 0: /*结束*/if(!StackEmpty(St)prin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论