可查可运行,注释详细,呵呵
#include
#include
using namespace std;
#define MAX 2 //停车场车位数
#define price 0.5//每分钟收取的费用
typedef struct time
{
int hour;
int min;
}Time;//定义时间结点
typedef struct node
{
string num;
Time reach;
Time leave;
}CarNode;//定义每辆车的牌号,进入时刻,开出时刻
typedef struct NODE
{
CarNode *stack[MAX+1];
int top;
}SeqStackCar;//用栈定义,构造停车场
typedef struct car
{
CarNode *data;
struct car *next;
}QueueNode;//用队列结点定义,构造停车场外的单个等候车辆
typedef struct Node
{
QueueNode *head;
QueueNode *rear;
}LinkQueueCar;//用队列定义,构造停车场外的等候便道
void InitStack(SeqStackCar *); //初始化堆栈函数声明
int InitQueue(LinkQueueCar *); //初始化队列头结点函数声明
int Arrival(SeqStackCar *,LinkQueueCar *); //车辆进入时登记函数声明
void Leave(SeqStackCar *,SeqStackCar *,LinkQueueCar *);//车辆离开时函数声明
void List(SeqStackCar,LinkQueueCar); /*查看停车场内车辆情况及
便道上车辆情况的函数声明*/
void main( )
{
SeqStackCar Enter,Temp;//初始栈,中转栈
LinkQueueCar Wait;//便道队列
int a;
InitStack(&Enter);
InitStack(&Temp);
InitQueue(&Wait);//初始化
while(1)
{
cout请按 1;
cout请按 2请按 3;
cout请按 4>a;
if(a>=1&&atop=0;
s->stack[s->top]=NULL;
}
int InitQueue(LinkQueueCar *Q)//队列初始化
{
Q->head=new QueueNode ;
if(Q->head!=NULL)
{
Q->head->next=NULL;
Q->rear=Q->head;
return 1;
}
else return -1;
}
void PRINT(CarNode *p,int room) //输出离开停车场的车辆情况
{
int A,B,C,D;
cout>p->leave.hour>>p->leave.min;
coutnum;
coutreach.hourreach.min;
coutleave.hourleave.min;
A=p->reach.hour;
B=p->reach.min;
C=p->leave.hour;
D=p->leave.min;
cout>p->num;
if(Enter->top
couttop>p->reach.hour>>p->reach.min;
coutstack[Enter->top]=p;// p是那辆汽车
return 1;
}
else //如果车位已满,则停靠在便道上
{
coutdata=p;
t->next=NULL;
W->rear->next=t;
W->rear=t;
return 1;
}
}
void Leave(SeqStackCar *Enter,SeqStackCar *Temp,LinkQueueCar *W)
{
int room;
CarNode *p,*t;
QueueNode *q;
if(Enter->top>0)
{
while(1)
{
couttop>room;
if(room>=1&&roomtop) break;
}
while(Enter->top>room)//从停车场堆栈向中转堆栈移动车辆,直到要离开车辆的位置停止
{
Temp->top++;
Temp->stack[Temp->top]=Enter->stack[Enter->top];
Enter->stack[Enter->top]=NULL;
Enter->top--;
}
p=Enter->stack[Enter->top];
Enter->stack[Enter->top]=NULL;
Enter->top--;
while(Temp->top>=1)//将中转堆栈中的车辆移回停车场堆栈
{
Enter->top++;
Enter->stack[Enter->top]=Temp->stack[Temp->top];
Temp->stack[Temp->top]=NULL;
Temp->top--;
}
couthead!=W->rear)&&Enter->top
t=q->data;
Enter->top++;
coutnumtopnum>t->reach.hour>>t->reach.min;
W->head->next=q->next;
if(q==W->rear) W->rear=W->head;
Enter->stack[Enter->top]=t;
delete q;
}
else couttop>0)
{
couttop;i++)
{
coutstack[i]->reach.hourstack[i]->reach.min;
coutstack[i]->numhead->next;
if(W->head!=W->rear)
{
coutdata->numnext;
}
}
else cout>tag;
if(tag>=1||tag
觉得文章有用就打赏一下文章作者
非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!
支付宝扫一扫打赏
微信扫一扫打赏