用链表,栈,队列实现简单的停车场项目
来源:互联网 发布:win7 apache ab测试 编辑:程序博客网 时间:2024/06/05 00:21
学习了链表,栈,队列之后写了一个停车场项目,但是功能还不是太完善,时间忘了插入,通过咨询别人,完善了时间函数,完成了这个项目。
问题描述:停车场是一个能放 n 辆车的狭长通道,只有一个大门,汽车按到达的先后次序停放。若车场满了,车要停在门外的便道上等候,一旦有车走,则便道上第一辆车进入。当停车场中的车离开时,由于通道窄,在它后面的车 要先退出,待它走后在依次进入。汽车离开时按停放时间收费。
基本功能要求:
(1)建立三个数据结构分别是:停放栈、让路栈、等候队列。
(2)输入数据模拟管理过程,数据(入或出,车号)
功能描述:进车登记、出车登记、按车牌号查询停车车辆信息、查询出入车记录、查询场内车辆信息、查询等候车辆信息、退出系统。
(1)linux系统编写(链表、栈、队列);
(2)进车登记:登记车牌号以及入场时间;
(3)出车登记:计算出停车时间,记录车辆车牌;
(4)按车牌号查询车辆信息:停车时间,是否来过停车场,是否还在停车场
(5)查询出入记录:所有车辆,包括已经离开的
(6)查询场内车辆信息:列出所有场内车辆信息
(7)查询等候车辆信息:显示等候车辆数量以及所有车牌号
(8)退出系统。
头文件#ifndef _PARK_H_#define _PARK_H_#define MAXSIZE 3#define FAILURE 10001struct node{char id[20];int month,day,hour,min,sec;time_t start,end;char info[10];struct node *next;};typedef struct node Node;typedef Node *LinkNode;struct stack{LinkNode top;int count;};typedef struct stack Stack;struct queue{LinkNode front;LinkNode rear;int flag;};typedef struct queue Queue;int settime(LinkNode n,time_t t);int timecopy(LinkNode n, LinkNode p);int InitStack(Stack *L);int InitQueue(Queue *S);int EnQueue(Queue *S, LinkNode i);int EnStack(Stack *L, LinkNode i);int EnCar(Stack *L, Queue *S, Queue *T);int OutCar(Stack *L, Stack *P, Queue *S, Queue*T);int Encar2(Stack *L, LinkNode S, Queue *T);int SearchInfo(Stack L, Queue T);int ShowInfo(Queue T);int EnInfo(Stack L);int WaitInfo(Queue S);#endif
接口函数#include <stdio.h>#include <stdlib.h>#include "park.h"#include <time.h>#include <string.h>void show(){system("clear");printf("********************************************\n\n");printf("******* WELCOME TO PARKING SYSTEM *******\n\n");printf("********************************************\n\n");sleep(1);system("clear");}void PrintInfo(){printf("***************************************************\n\n");printf("* 1.进车登记 *\n");printf("* 2.出车登记 *\n");printf("* 3.按车牌号查询车辆信息 *\n");printf("* 4.查询出入记录 *\n");printf("* 5.查询场内车辆信息 *\n");printf("* 6.查询等候车辆信息 *\n");printf("* 7.退出 *\n");printf(" 收费标准:每秒2元!车在候车场不收费! \n\n");printf("***************************************************\n\n");printf("请输入你的选择 :\n");}int settime(LinkNode n,time_t t){ struct tm *pt;time(&t);pt = localtime(&t);n->month = pt->tm_mon+1;n->day = pt->tm_mday;n->hour = pt->tm_hour;n->min = pt->tm_min;n->sec = pt->tm_sec;}int timecopy(LinkNode n, LinkNode p){n->start = p->start;n->month = p->month;n->day = p->day;n->hour = p->hour;n->min = p->min;n->sec = p->sec;}int InitStack(Stack *L){L->top = NULL;L->count = 0;}int InitQueue(Queue *S){S->front = (LinkNode)malloc(sizeof(Node));S->rear = S->front;S->rear->next = NULL;S->flag = 0;}int EnQueue(Queue *S,LinkNode i){S->rear->next = i;S->rear = i;i->next = NULL;S->flag++;}int EnStack(Stack *L, LinkNode i){i->next = L->top;L->top = i;L->count++;}int EnCar(Stack *L, Queue *S, Queue *T){time_t t;struct tm *pt;LinkNode n = (LinkNode)malloc(sizeof(Node));LinkNode m = (LinkNode)malloc(sizeof(Node));printf("请输入你的车牌号:\n");scanf("%s",n->id);if(L->count >= MAXSIZE){printf("停车场已满,请进入候车场等待!\n");EnQueue(S,n);return FAILURE;}time(&t);n->start = t;pt = localtime(&t); settime(n,t);printf("停车时间是:%d月%d日%d:%d:%d\n",n->month,n->day,n->hour,n->min,n->sec);timecopy(m,n);strcpy(m->info,"Parking!");strcpy(m->id, n->id);EnQueue(T,m);EnStack(L,n);printf("停车成功!\n");}int OutCar(Stack *L, Stack *P, Queue *S,Queue *T){long int ti;LinkNode m = (LinkNode)malloc(sizeof(Node));time_t t;struct tm *pt;char i[20];printf("请输入你要开走的车牌号:\n");scanf("%s",i);while(L->top){LinkNode p= L->top;if(strcmp((p->id),i) == 0){break;}L->top = p->next;EnStack(P,p);} if(L->top == NULL){while(P->top){LinkNode k = P->top;P->top = k->next;EnStack(L,k);}printf("此车不在此停车场!\n");return 0;}LinkNode l = L->top;time(&t);l->end = t;pt = localtime(&t);settime(l,t);ti = l->end - l->start;printf("|*****************************|\n");printf("| 账单 |\n");printf("|恭喜你成功开走了这辆车! |\n");printf("|离开时间是:%d月%d日%d:%d:%d! |\n",l->month,l->day,l->hour,l->min,l->sec);printf("|停车时长:%d s! |\n", ti);printf("|停车费用:%d元! |\n", ti*2);printf("|*****************************|\n");timecopy(m,l);strcpy(m->info,"Leave! ");strcpy(m->id, l->id);EnQueue(T,m);L->top = l->next;free(l);L->count--;while(P->top){LinkNode k = P->top;P->top = k->next;EnStack(L,k);}if((S->flag) > 1){printf("候车场车牌为%s的车可以停车!\n",S->front->next->id);LinkNode j = S->front->next;S->front->next = j->next;Encar2(L,j,T);S->flag--;return;}else if(S->flag == 1){printf("候车场车牌为%s的车可以停车!\n",S->front->next->id);LinkNode j = S->front->next;S->front->next = j->next;S->rear = S->front;Encar2(L,j,T);S->flag--;return 0;}else return;}int Encar2(Stack *L, LinkNode S, Queue *T){LinkNode m = (LinkNode)malloc(sizeof(Node));time_t t;struct tm *pt;time(&t);S->start = t;pt = localtime(&t);settime(S,t);printf("停车时间是:%d月%d日%d:%d:%d\n",S->month,S->day,S->hour,S->min,S->sec);timecopy(m,S);strcpy(m->info,"Parking!");strcpy(m->id, S->id);EnQueue(T,m);EnStack(L,S);printf("停车成功!\n");}int SearchInfo(Stack L, Queue T){char n[10];printf("请输入你想查询的车牌号:\n");scanf("%s",n);LinkNode p = T.front->next;while(p){if(strcmp(p->id,n) == 0){break;}p = p->next;}if(p == NULL){printf("没有此车!\n");return;}LinkNode l = p;printf("车牌号:%s 状态:%s 时间:%d月%d日%d:%d:%d\n",l->id,l->info,l->month,l->day,l->hour,l->min,l->sec);p = p->next;if(p != NULL){while(p){if(strcmp(p->id,n) == 0){printf("车牌号:%s 状态:%s 时间:%d月%d日%d:%d:%d\n",p->id,p->info,p->month,p->day,p->hour,p->min,p->sec);break;}p = p->next;}}LinkNode q = L.top;while(q){if(strcmp(q->id,n) == 0){printf("车还在停车场中!\n");break;}q = q->next;}if(q == NULL){printf("车不在停车场中!\n");}}int ShowInfo(Queue T){if(T.front->next == NULL){printf("没有车辆信息可以查询!\n");return;}LinkNode q = T.front->next;while(q){printf("车牌号:%s 状态:%s 时间:%d月%d日%d:%d:%d\n",q->id,q->info,q->month,q->day,q->hour,q->min,q->sec);q = q->next;}}int EnInfo(Stack L){LinkNode p = L.top;while(p != NULL){printf("车牌号:%s 停车时间:%d月%d日%d:%d:%d\n",p->id,p->month,p->day,p->hour,p->min,p->sec);p = p->next;}}int WaitInfo(Queue S){printf("现在有%d辆车在等待!\n",S.flag);if(S.flag == 0){return 0;}LinkNode p = S.front;while(p->next != NULL){printf("车牌号:%s\n",p->next->id);p = p->next;}}
主函数#include <stdio.h>#include <stdlib.h>#include "park.h"int main(){Stack in,tmp;Queue wait,record;InitQueue(&record);InitStack(&in);InitStack(&tmp);InitQueue(&wait);char choice[8] = {0};show();while (1){PrintInfo();scanf("%s", choice);switch (atoi(&choice[0])){case 1:printf("1.进车登记\n");EnCar(&in,&wait,&record);break;case 2:printf("2.出车登记\n");OutCar(&in,&tmp,&wait,&record);printf("***********************************************\n\n");break;case 3:printf("3.按车牌号查询车辆信息\n");SearchInfo(in,record);printf("***********************************************\n\n");break;case 4:printf("4.查询出入记录\n");ShowInfo(record);printf("***********************************************\n\n");break;case 5:printf("5.查询场内车辆信息\n");EnInfo(in);printf("***********************************************\n\n");break;case 6:printf("6.查询等候车辆信息\n");WaitInfo(wait);printf("***********************************************\n\n");break;case 7:exit(1);break;default:printf("ERROR!\n");break;}}return 0;}
阅读全文
0 0
- 用链表,栈,队列实现简单的停车场项目
- 用栈和队列实现简单的停车场管理系统
- java栈+队列实现简单的停车场管理问题
- 简单的停车场管理,栈,队列。
- 栈与队列实现的停车场系统
- 停车场管理 -- 队列 栈 实现
- 栈和队列 实现停车场
- 用栈和队列实现的停车场管理系统
- 栈和队列实现停车场(2)
- 队列实现-停车场管理
- 停车场栈和队列的调用
- refresh的停车场 (栈+队列)
- 栈与队列--refresh的停车场
- 队列和栈的应用 ------ 停车场
- refresh的停车场(栈+队列)
- 栈与队列--停车场
- 第七周 数据结构实践——停车场模拟(栈和队列综合)【项目6 - 停车场模拟】
- 停车栈让路栈等候队列完成停车场项目
- Python编程:从入门到实践的动手试一试答案(第四章)
- python实现汉诺塔移动
- 看完这些你就懂了主力
- 第13周项目3-是否二叉排序树
- 通过牛腩反思以往
- 用链表,栈,队列实现简单的停车场项目
- 如何查看robots协议?怎么写?
- 基于onvif开发中soap_call___tds__GetCapabilities函数调用返回错误值是4
- 第13周 【项目三】 验证二叉排序树相关算法
- Android实战——GreenDao3.2的使用,爱不释手
- 数据结构第十三周项目1--验证算法
- Charles
- Android安装GDB/GDB server
- 第十二周项目二