如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
停车场管理小程序,实现停车,便道等待停车等基本功能,由两个栈,一个队列完成,一个用于停车,另一个用于缓存#include<stdio.h>#include<stdlib.h>#defineMAX8//--------------typedefstructCAR{intnum;intcometime;}car;structstack{car*sta[MAX+1];inttop;};structqnode{car*data;structqnode*next;};structquene{structqnode*front;structqnode*rear;};//---------voidstack_init(structstack*s){s->top=0;}voidquene_init(structquene*q){q->front=(structquene*)malloc(sizeof(structquene));q->front->next=NULL;q->rear=q->front;}//-------------voidcome(structstack*s,structquene*q){staticinti=0;car*p=(car*)malloc(sizeof(car));structqnode*t=(structqnode*)malloc(sizeof(structqnode));printf("登记车牌号:\t");scanf("%d",&(p->num));if((s->top)<MAX){printf("有车位请进入\n");s->top++;printf("开始时间:\t");scanf("%d",&(p->cometime));s->sta[s->top]=p;}else{i++;printf("没车位,有%d辆车在等待\n",i);t->data=p;t->next=NULL;q->rear->next=t;q->rear=t;}}voidlev(structstack*s,structstack*t,structquene*q){intg;car*p,*k;structqnode*bian;printf("车位1-%d\n",s->top);printf("谁想离开:\t");scanf("%d",&g);while(s->top>g){if(s->top==0)printf("没车了\n");t->top++;t->sta[s->top]=s->sta[s->top];s->sta[s->top]=NULL;s->top--;}p=s->sta[s->top];printf("离开车牌号:%d\n",p->num);s->sta[s->top]=NULL;s->top--;while(t->top>0){s->top++;s->sta[s->top]=t->sta[s->top];t->top--;}while((q->front!=q->rear)&&(s->top<MAX)){bian=(structqnode*)malloc(sizeof(structqnode));bian=q->front->next;k=bian->data;printf("有车位,便道上车牌%d进入\n",k->num);s->top++;q->front->next=bian->next;if(q->rear==bian)q->front=q->rear;s->sta[s->top]=k;free(bian);}if(q->front==q->rear)printf("便道没车了\n");}voidview(structstack*s,structquene*q){printf("停车场情况***\n");inti;if(s->top>0){for(i=1;i<=(s->top);i++){printf("车牌:%d在停车场内\n",s->sta[i]->num);}}elseprintf("停车场内没车\n");structqnode*t;t=(structqnode*)malloc(sizeof(structqnode));t=q->front->next;printf("便道情况***\n");while(q->front!=q->rear){printf("车牌:%d在便道\n",t->data->num);q->front=q->front->next;t=q->