资源描述:
《c语言实现停车场管理系统.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#include#defineSize2#defineprice5typedefstruct{charnum[20];intreachtime;intleavetime;}carinfo;typedefstructstack{carinfocar[5];inttop;}Stack;typedefstructNode{carinfodata;structNode*next;}QueueNode;typedefstruct{QueueNode*fr
2、ont;QueueNode*rear;}Queue,*linkQueue;intEnterQ(Queue*Q,carinfox);intinistack(Stack*S)//初始化栈{S->top=-1;return1;}voidPush(Stack*S,carinfox)//进栈操作{S->top++;S->car[S->top]=x;printf("进站成功!");}voidPop(Stack*S,carinfox)//出栈操作{if(S->top=-1)printf("空栈,无法出栈!");x=S->car[S->top];S
3、->top--;printf("出栈成功!");}IsEmpty(Stack*S)//判断栈空{if(S->top==-1)return1;elsereturn0;}intiniQueue(Queue*Q)//初始化便道{Q->front=(QueueNode*)malloc(sizeof(QueueNode));//申请节点if(Q->front!=NULL){Q->rear=Q->front;Q->front->next=NULL;return1;}elsereturn0;}intEnterQ(Queue*Q,carinfox)
4、//进便道{QueueNode*newNode;newNode=(QueueNode*)malloc(sizeof(QueueNode));if(newNode!=NULL){newNode->data=x;newNode->next=NULL;Q->rear->next=newNode;Q->rear=newNode;return1;}elsereturn0;}intDeleteQ(Queue*Q,carinfox)//出便道{QueueNode*p;p=Q->front->next;if(Q->front==Q->rear)//
5、判断便道是否有车return0;x=p->data;if(p->next==Q->rear){Q->rear=Q->front;Q->front->next=NULL;}Q->front->next=p->next;free(p);return1;}voidLpush(Stack*S,carinfox){Push(S,x);//进临时栈}voidLPop(Stack*S,carinfox){Pop(S,x);}intArrive(Stack*S,Queue*Q)//车辆到达{carinfox;inta;printf("输入车牌号:"
6、);scanf("%s",x.num);printf("请输入进车场的时间:");scanf("%d",&x.reachtime);if(S->top==Size-1){printf("车场已满,不能进入,进便道");a=EnterQ(Q,x);//递归调用进便道操作if(a==1){printf("OK");}elseprintf("No!");}else{Push(S,x);}return1;}intDeparture(Stack*S)//车辆离开操作{intmoney;charx[20];Stack*p=NULL;in
7、tpoint1=S->top;intpoint2;printf("请输入要离去的车牌号:");scanf("%s",x);intleavetime;while(point1!=-1&&point2!=-1){if(strcmp(S->car[point1].num,x)==0)//匹配函数,是否输入的信息与车场信息匹配{printf("请输入要离开的时间:");scanf("%d",&leavetime);for(;point1!=S->top;point1++,point2++)//扫描直到结束S->car[point1]=S->
8、car[point2];//如果找到了,出车S->top--;printf("成功出车场");money=(leavetime-S->car[point1].reachtime)*price;.//费用信息printf("费用:%