# include<stdlib.h>
# include<stdio.h>
# define N 2 //通道允许的最大停车数量,可重新设置
# define NULL 0 //空值
# define PRICE 1 //收费单价,可重新设置
typedef struct car_infor
{
int licen_tag;
}SElemType;
typedef struct
{
SElemType *base1; //通道的栈底指针
SElemType *top1; //通道的栈顶指针
SElemType *base2; //临时道的栈底指针
SElemType *top2; //临时道的栈顶指针
}Stack;
typedef struct Qnode
{
int licen_tag;
struct Qnode *next;
}Qnode,*QueuePtr;
typedef struct
{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
void initStack(Stack &S) //初始化通道与临时道
{
S.
base1=(SElemType
*)malloc(N
*sizeof(SElemType
));
S.top1=S.base1;
S.
base2=(SElemType
*)malloc(N
*sizeof(SElemType
));
S.top2=S.base2;
}
void initQueue(LinkQueue &Q) //初始化便道
{
Q.
front=Q.
rear=(QueuePtr
)malloc(sizeof(Qnode
));
Q.front->next=NULL;
}
void Push1
(Stack
&S
,int licen_tag
,int time) //车辆进通道
{
S.top1->licen_tag=licen_tag;
S.top1++;
}
void Push2(Stack &S) //让路的车辆从通道暂时离开,进临时道
{
S.top2->licen_tag=S.top1->licen_tag;
S.top2++;
S.top1--;
}
void Pop(Stack &S) //车辆从临时道回到通道
{
S.top2--;
S.top1->licen_tag=S.top2->licen_tag;
S.top1++;
}
void EnQueue
(LinkQueue
&Q
,int licen_tag
,int time) //通道满时,车辆进便道
{
QueuePtr p;
p
=(QueuePtr
)malloc(sizeof(Qnode
));
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
p->licen_tag=licen_tag;
}