#include<iostream>
#include<conio.h>
#include<iomanip>
#include<fstream>
#include<string>
#include <stdlib.h>
#include <windows.h>
using namespace std;
#define Max_Size 2//停车的最大容量
#define HourFare 2 //每小时的停车费用
int CountForStack=0; //栈里现有的车数
int CountForQueue=0; //排队等候的车数
typedef struct
{
char Condition;//到达或者离开的状态
int arrivetime;//到达时间,默认为-1,表示没有到达
int leavetime;//离开时间,默认为-1,表示没有离开
int License;//车牌号
}
CarNode;//保存每辆车的信息
typedef struct//栈的定义
{
CarNode *base;//栈底指针
CarNode *top;//栈顶指针
int Stacksize;//栈的最大容量
}
CarStack;
typedef struct QNode
{
char Condition;//到达或者离开的状态
int Arrivetime;//到达时间,默认为-1,表示没有到达
int Leavetime;//离开时间,默认为-1,表示没有离开
int License;//车牌号
QNode *next;
}
QNode;
typedef struct//队列的定义
{
QNode *front;//对头指针
QNode * rear;//队尾指针
}
Queue;
bool InitStack(CarStack &S1)//初始化栈 S1
{
S1.base=(CarNode*)malloc(Max_Size*sizeof(CarNode));
if(!S1.base)
{
cout<<"栈 S1 内存分配失败"<<endl;
return false;
}
S1.top=S1.base;
S1.Stacksize=Max_Size;
return true;
}
bool InitQueue(Queue &Q)
{
Q.front=(QNode*)malloc(sizeof(QNode));
if(!Q.front)
{
cout<<"队列 Q 内存分配失败!"<<endl;
return false;
}
Q.rear=Q.front;
Q.front->next=NULL;
return true;
}
bool EnQueue(Queue &Q,QNode &e)//插入元素 e 为 Q 的新的队尾元素
{
QNode *p=(QNode *)malloc(sizeof(QNode));
if(!p)
{
cout<<"p 内存分配失败"<<endl;
return false;
}
p->Arrivetime=e.Arrivetime;
p->Leavetime=e.Leavetime;
p->Condition=e.Condition;
p->License=e.License;//将 e 赋给 P
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return true;
}
bool DeQueue(Queue &Q,QNode &t)//出队列函数
{
if(Q.front==Q.rear)
{
cout<<"队列为空!"<<endl;
return false;
}
QNode *p=Q.front->next;
t.Arrivetime=p->Arrivetime;
t.Condition=p->Condition;
t.Leavetime=p->Leavetime;
停车场
最新推荐文章于 2022-03-23 21:41:57 发布