云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 数据结构停车场管理实验报告C++

数据结构停车场管理实验报告C++

  • 62 次阅读
  • 3 次下载
  • 2025/12/12 3:57:13

}

free(p); return OK;

源程序

Stop1.h:

#include #include #include #include

//------------------------函数结果状态代码 #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0

#define TNFEASIBLE -1 #define OVERFLOW -2

//Status 是函数的类型,其值是函数结果状态代码 typedef int Status;

#define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 #define MONEY 3 Stop2.h:

#include\

typedef struct ElemType{ char a[3]; int num; int time; }ElemType;

typedef struct SqStack{ ElemType *base; ElemType *top; int stacksize; }SqStack;//栈的表示 typedef struct QNode{ ElemType data; struct QNode *next;

}QNode,*QueuePtr;//队列的表示 typedef struct LinkQueue{ QueuePtr front;//队头指针

QueuePtr rear;//队尾指针

}LinkQueue;

Status InitStack(SqStack &S);//构造空栈 Status Push(SqStack &S,ElemType e);//进栈 Status Pop(SqStack &S,ElemType &e);//出栈

Status InitQueue(LinkQueue &Q);//构造一个空队列 Status EnQueue(LinkQueue &Q,ElemType e);//入队 Status DeQueue(LinkQueue &Q,ElemType &e);//出队

Stop.cpp:

#include\

Status InitStack(SqStack &S){//构造空栈

S.base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType)); if(!S.base) exit(OVERFLOW); S.top=S.base;

S.stacksize=STACK_INIT_SIZE; return OK; }

Status Push(SqStack &S,ElemType e){//插入元素e为新的栈顶元素 if(S.top-S.base>=S.stacksize){//栈满,追加存储空间 S.base=(ElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(ElemType)); if(!S.base) exit(OVERFLOW); S.top=S.base+S.stacksize; S.stacksize+=STACK_INIT_SIZE; } *S.top++=e; return OK; }

Status Pop(SqStack &S,ElemType &e){//出栈 if (S.top==S.base) return OK; e=*--S.top; return OK; }

/***********************************************************************队列*/ Status InitQueue(LinkQueue &Q){//构造一个空队列 Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode)); if(!Q.front) exit(OVERFLOW); Q.front->next=NULL; return OK; }

Status EnQueue(LinkQueue &Q,ElemType e){//插入元素e为Q的新队列 struct QNode *p;

p=(QueuePtr)malloc(sizeof(QNode)); if(!p) exit(OVERFLOW); p->data=e;p->next=NULL; Q.rear->next=p; Q.rear=p; return OK; }

Status DeQueue(LinkQueue &Q,ElemType &e){ struct QNode *p; if(Q.front=Q.rear) return ERROR; p=Q.front->next=p->next; if(Q.rear==p) Q.rear=Q.front; free(p); return OK; }

Stop_main.cpp: #include\ main(){ int i,t,f,m,n,s1_num,Q_num; struct SqStack s1,s2; struct LinkQueue Q; struct ElemType e,e1; s1_num=0;Q_num=0;t=0;m=0; InitStack(s1);InitStack(s2);InitQueue(Q); printf(\停车场的容量是:\ scanf(\ printf(\输入车辆信息(E为退出,A为进入标志,D为离开标志,车牌号 时间空格隔开):\\n\ scanf(\ while(strcmp(e1.a,\ if(strcmp(e1.a,\当有车辆进来的时候 if(s1_num

else Push(s2,e);} if(t==0&&m==0){printf(\此车为便道内车,故无需收费\\n\ while(s2.top!=s2.base){ Pop(s2,e);Push(s1,e);s1_num++;} if(Q.front!=Q.rear){ DeQueue(Q,e);Push(s1,e);s1_num++;} } else printf(\错误\\n\ printf(\输入数据\\n\ scanf(\

运行结果

搜索更多关于: 数据结构停车场管理实验报告C++ 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

} free(p); return OK; 源程序 Stop1.h: #include #include #include #include //------------------------函数结果状态代码 #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define TNFEASIBLE -1 #define OVERFLOW -2 //Status 是函数的类型,其值是函数结果状态代码 typedef int Status; #define STACK_INIT_SIZE 100 #d

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com