⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bb.cpp

📁 一个停车场管理的模拟程序!VC++6.0下开发~!
💻 CPP
字号:
#include<stdlib.h>
#include<stdio.h>
typedef struct{
	char flag;
	int num;
	int time;
}car_infor;
typedef struct{
	car_infor *base;
	car_infor *top;
}sqstack;
typedef struct qnode{
	car_infor data;
	struct qnode *next;
}qnode,*queueptr;
typedef struct{
	queueptr front;
	queueptr rear;
}linkqueue;
//栈的基本操作的算法描述
sqstack initstack(){
	sqstack s;
	s.base=(car_infor*)malloc(2*sizeof(car_infor));
	s.top=s.base;
	return s;
}
void push(sqstack &s,car_infor e){
	*s.top++=e;
}
car_infor pop(sqstack &s){
	car_infor e;
	e=*--s.top;
	return e;
}
//队列的基本操作
linkqueue initqueue(){
	linkqueue q;
	q.front=q.rear=(queueptr)malloc(sizeof(qnode));
	q.front->next=NULL;
	return q;
}
void enqueue(linkqueue &q,car_infor e){
	queueptr p;
	p=(queueptr)malloc(sizeof(qnode));
	p->data=e;
	p->next=NULL;
	q.rear->next=p;
	q.rear=p;
}
car_infor dequeue(linkqueue &q){
	car_infor e;
	queueptr p;
	p=q.front->next;
	e=p->data;
	q.front->next=p->next;
	if(q.rear=p) q.rear=q.front;
	free(p);
	return e;
}
void main(){
			sqstack park,lpark;//park为停车场,lpark为临时是停放为要离开的汽车让路的汽车的地方
			linkqueue path;//path为等待进入停车场的车所停的便道
			car_infor e,s;
			int i=0;
			park=initstack();
			lpark=initstack();
			path=initqueue();
			printf("Please Input a car's information::::::::\n");
			scanf("%c,%d,%d",&e.flag,&e.num,&e.time);
			while(e.flag!='E')
				{
					if(e.flag=='A')
						{
							if((park.top-park.base)<2)
								{
									push(park,e);
									printf("the arriving car's location is park %d\n",park.top-park.base);
								}
							else
								{
									i++;
									enqueue(path,e);
									printf("the arriving car's location is path %d\n",i);
								}
						}
					else 
						if(e.flag=='D')
							{
								while((park.top-1)->num!=e.num)
									{	
										s=pop(park);
										push(lpark,s);
									}
								s=pop(park);
								printf("the depating car's time is %d,fee is %d yuan\n",e.time,e.time-s.time);
								while(lpark.base!=lpark.top)
									{
										s=pop(lpark);
										push(park,s);
									}
								if(path.front!=path.rear)
									{
										i--;
										path.front->next->data.time=e.time;
										s=dequeue(path);
										push(park,s);
									}
						printf("please input a car's¥¥¥¥¥ information\n");
					    scanf("%c,%d,%d",&e.flag,&e.num,&e.time);
							 }
						printf("please input a car's information\n");
					    scanf("%c,%d,%d",&e.flag,&e.num,&e.time);
						
					}
		}
			

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -