课题设计 停车场车辆管理系统C语言版数据结构.docx
《课题设计 停车场车辆管理系统C语言版数据结构.docx》由会员分享,可在线阅读,更多相关《课题设计 停车场车辆管理系统C语言版数据结构.docx(13页珍藏版)》请在冰豆网上搜索。
![课题设计 停车场车辆管理系统C语言版数据结构.docx](https://file1.bdocx.com/fileroot1/2022-11/15/4db9f529-6b74-4111-868c-71355496208d/4db9f529-6b74-4111-868c-71355496208d1.gif)
课题设计停车场车辆管理系统C语言版数据结构
//设停车场是一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。
//汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列(大门在最南端,最先到达的第一辆车停放在车场的最北端),
//若车场内已停满n辆汽车,则后来的车只能在门外的便道上等候,一旦有车开走,则排在便道上的第一辆车即可开入;
//当停车场内某辆车要离开时,在它之后进入的车辆必须先退出车长为它让路,待该车开出大门外,
//其他车辆再按原次序进入车场,每辆停放在车场的车在它离开停车场时必须按它停留的时间长短交纳费用。
//基本要求:
以栈模拟停车场,以队列模拟车场外的便道
//部分源代码(栈和队列的数据结构自己定义,在清华版的数据结构课本上有详细的描述)
//停车场管理系统
//停车场管理系统
#include
typedefstructCar{
//结构体:
车辆Car
intnumber;
intinTime;
intoutTime;
}Car;
typedefCarUser;//用户自定义类型
#defineFEIYONG0.05//停车费用单价
#defineMAXSIZE5//停车场容量
//--------------系统库函数------------------
#include"stdlib.h"
//--------------通用变量、常量、类型声明------------------
#defineTRUE1
#defineFALSE0
#defineOK1
#defineERROR0
#defineOVERFLOW-2
typedefintStatus;
typedefUserSElemType;
//---------------存储表示---------------------
#defineSTACK_INIT_SIZE100
#defineSTACKINCREMENT10
typedefstruct{
SElemType*base;
SElemType*top;
intstacksize;
}SqStack;
//---------------函数原型---------------------
//StatusInitStack(SqStack&S);
//构造空栈
//StatusDestroyStack(SqStack&S);
//销毁栈S
//StatusClearStack(SqStack&S);
//置空
//StatusStackEmpty(SqStackS);
//判空;空:
TRUE,不空:
FALSE。
//intStackLength(SqStackS);
//返回S的元素的个数,即栈的长度。
//StatusGetTop(SqStackS,SElemType&e);
//若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERROR。
//StatusPush(SqStack&S,SElemTypee);
//插入元素e为新的栈顶元素
//StatusPop(SqStack&S,SElemType&e);
//若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR。
//StatusStackTraverse(SqStackS,Status(*visit)());
//从栈底到栈顶依次对栈中每个元素调用函数visit()。
一旦visit()失败,则操作失败。
//---------------基本操作---------------------
StatusInitStack(SqStack&S){
//构造空栈
S.base=(SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if(!
S.base)exit(OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
returnOK;
}//InitStack
StatusDestroyStack(SqStack&S){
//销毁栈S
free(S.base);
returnOK;
}//DestroyStack
StatusClearStack(SqStack&S){
//置空
returnOK;
}//ClearStack
//StatusClearStack(SqStack&S);
//置空
StatusStackEmpty(SqStackS){
//判空;空:
TRUE,不空:
FALSE。
if(S.top==S.base)returnTRUE;
elsereturnFALSE;
}//QueueEmpty
intStackLength(SqStackS){
//返回S的元素的个数,即栈的长度。
returnS.top-S.base;
}
StatusGetTop(SqStackS,SElemType&e){
//若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERROR。
if(S.top==S.base)returnERROR;
e=*(S.top-1);
returnOK;
}//GetTop
StatusPush(SqStack&S,SElemTypee){
//插入元素e为新的栈顶元素
if(S.top-S.base>=S.stacksize){//栈满,追加存储空间
S.base=(SElemType*)realloc(S.base,
(S.stacksize+STACKINCREMENT)*sizeof(SElemType));
if(!
S.base)exit(OVERFLOW);//存储分配失败
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
returnOK;
}//Push
StatusPop(SqStack&S,SElemType&e){
//若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR。
if(S.top==S.base)returnERROR;
e=*--S.top;
returnOK;
}//Pop
StatusStackTraverse(SqStackS){//,Status(*visit)()){
//从栈底到栈顶依次对栈S中每个元素调用函数visit()。
一旦visit()失败,则操作失败。
for(SElemType*p=S.base;pprintf("%d\n",p->number);
returnOK;
}//StackTraverse
typedefintStatus;
typedefUserQElemType;
//---------------存储表示---------------------
typedefstructQNode{
QElemTypedata;
structQNode*next;
}QNode,*QueuePtr;
typedefstruct{
QueuePtrfront;
QueuePtrrear;
}LinkQueue;
//---------------函数原型---------------------
//StatusInitQueue(LinkQueue&Q);
//构造空队列Q
//StatusDestroyQueue(LinkQueue&Q);
//销毁队列Q
//StatusClearQueue(LinkQueue&Q);
//置空
//StatusQueueEmpty(LinkQueueQ);
//判空;空:
TRUE,不空:
FALSE。
//intQueueLength(LinkQueueQ);
//返回S的元素的个数,即队列的长度。
//StatusGetHead(LinkQueueQ,QElemType&e);
//若队列不空,则用e返回S的队头元素,并返回OK;否则返回ERROR。
//StatusEnQueue(LinkQueue&Q,QElemTypee);
//插入元素e为新的队尾元素
//StatusDeQueue(LinkQueue&Q,QElemType&e);
//若队列不空,则删除Q的队头元素,用e返回其值,并返回OK;否则返回ERROR。
//StatusQueueTraverse(LinkQueueQ,Status(*visit)());
//从队头到队尾依次对队列Q中每个元素调用函数visit()。
一旦visit()失败,则操作失败。
//---------------基本操作---------------------
StatusInitQueue(LinkQueue&Q){
//构造空队列Q
Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
if(!
Q.front)exit(OVERFLOW);
Q.front->next=NULL;
returnOK;
}//InitQueue
StatusDestroyQueue(LinkQueue&Q){
//销毁队列Q
while(Q.front){
Q.rear=Q.front->next;
free(Q.front);
Q.front=Q.rear;
}
returnOK;
}//DestroyQueue
//StatusClearQueue(LinkQueue&Q);
//置空
StatusQueueEmpty(LinkQueueQ){
//判空;空:
TRUE,不空:
FALSE。
if(Q.front==Q.rear)returnTRUE;
elsereturnFALSE;
}//QueueEmpty
//intQueueLength(LinkQueueQ);
//返回Q的元素的个数,即队列的长度。
StatusGetHead(LinkQueueQ,QElemType&e){
//若队列不空,则用e返回Q的队头元素,并返回OK;否则返回ERROR。
if(Q.front==Q.rear)returnERROR;
e=Q.front->next->data;
returnOK;
}//GetHead
StatusEnQueue(LinkQueue&Q,QElemTypee){
//插入元素e为新的队尾元素
QueuePtrp;
p=(QueuePtr)malloc(sizeof(QNode));
if(!
p)exit(OVERFLOW);
p->data=e;p->next=NULL;
Q.rear->next=