📄 simulation.h
字号:
typedef LinkList EventList; //事件链表类型,定义为有序链表
EventList ev; //事件表
Event en; //事件
LinkQueue Q; //等候理发的顾客队列
QElemType customer; //顾客记录
int t2,t1,Totaltime,CustomerNum,CloseTime,k,CurrentChair; //累计顾客逗留时间,顾客数
float Totallength;
void OpenForDay()
{ //初始化操作
t1=t2=0;
Totaltime=0;
Totallength=0;
CustomerNum=0;
InitList(ev);
en.OccurTime=0;
en.NType=0;
OrderInsert(ev,en);
InitQueue(Q);
cout<<"Input the chairs' number: ";
cin>>k;
CurrentChair=k;
cout<<"Input CloseTime:";
cin>>CloseTime;
cout<<endl;
}
void CustomerArrived()
{ //处理顾客到达事件
QElemType e1;
ElemType e;
int durtime,intertime,R;
CustomerNum++;
R=rand();
durtime=15+R%50;
intertime=2+R%10;
/* cout<<"Input durtime: ";
cin>>durtime;
cout<<"Input intertime: ";
cin>>intertime;
cout<<endl;*/
e.OccurTime=en.OccurTime+intertime;
if(e.OccurTime>t1) t1=e.OccurTime;
e.NType=0;
if(e.OccurTime<CloseTime)
OrderInsert(ev,e);
if(CurrentChair>0)
{
e.OccurTime=en.OccurTime+durtime;
if(e.OccurTime>t1) t1=e.OccurTime;
e.NType=1;
OrderInsert(ev,e);
Totaltime+=durtime;
CurrentChair--;
}
else
{
e1.ArrivalTime=en.OccurTime;
e1.Duration=durtime;
EnQueue(Q,e1);
Totallength+=QueueLength(Q); //累计队长
}
}
void CustomerDeparture()
{
int Departuretime;
ElemType e;
if(!QueueEmpty(Q))
{
DeQueue(Q,customer);
Departuretime=en.OccurTime+customer.Duration;
if(Departuretime>t2) t2=Departuretime;
e.OccurTime=Departuretime;
e.NType=1;
OrderInsert(ev,e);
Totaltime+=Departuretime-customer.ArrivalTime;
}
else CurrentChair++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -