(汽车行业)汽车管理程序

上传人:管****问 文档编号:127939756 上传时间:2020-04-07 格式:DOC 页数:6 大小:44.07KB
返回 下载 相关 举报
(汽车行业)汽车管理程序_第1页
第1页 / 共6页
(汽车行业)汽车管理程序_第2页
第2页 / 共6页
(汽车行业)汽车管理程序_第3页
第3页 / 共6页
(汽车行业)汽车管理程序_第4页
第4页 / 共6页
(汽车行业)汽车管理程序_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《(汽车行业)汽车管理程序》由会员分享,可在线阅读,更多相关《(汽车行业)汽车管理程序(6页珍藏版)》请在金锄头文库上搜索。

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(si

2、zeof(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

3、-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)

4、;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; /*出队的对

5、头元素到参数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为候车场

6、*/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(候车场位置:%

7、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(!StackEmpt

8、y(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)printf( 停车场中的车辆:);DispStack(St);if(!QueueEmpty(Qu)printf(候车场中的数量:);DispQueue(Qu);break;default:printf(输入的命令错误n);break;while(comm!=0);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 经营企划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号