Compare commits

..

1 Commits

Author SHA1 Message Date
刘彩月 47962c3335 Merge branch 'master' into 刘彩月
1 year ago

File diff suppressed because it is too large Load Diff

@ -40,6 +40,7 @@ typedef struct
QueuePtr rear;//队尾指针
}LinkQueue;
EventList ev;//事件表
Event en;//事件
LinkQueue q[5];//四个客户队列
@ -107,12 +108,9 @@ void Bank_Simulation(int CloseTime) // 银行业务模拟,统计一天内客
}
int cmp(Event a, Event b)//比较事件发生先后
{
if (a.OccurTime > b.OccurTime)
return 1;
if (a.OccurTime = b.OccurTime)
return 0;
if (a.OccurTime < b.OccurTime)
return -1;
if (a.OccurTime > b.OccurTime) return 1;
if (a.OccurTime = b.OccurTime) return 0;
if (a.OccurTime < b.OccurTime) return -1;
}
void OpenForDay()//银行开门
@ -164,18 +162,19 @@ void CustomerArrived() // 客户进门
}
}
void CustomerDepature()//客户离开
{
int i = en.NType;
DeQueue(q[i], customer);//删除第i队列的排头客户
TotalTime += en.OccurTime - customer.ArrivalTime;//累计客户逗留时间
if (!QueueEmpty(q[i]))
{
if (!QueueEmpty(q[i])) {
GetHead(q[i], customer);
OrderInsert(ev, { en.OccurTime + customer.Duration, i }, cmp);//插入事件
}
}
int Minimum(LinkQueue Q[5])//求长度最短队列
{
int minLength = QueueLength(Q[1]);
@ -191,6 +190,7 @@ int Minimum(LinkQueue Q[5]) // 求长度最短队列
return i;
}
Status InitList(LinkList& L)//链表初始化
{
L = (LinkList)malloc(sizeof(LNode));
@ -265,14 +265,12 @@ void PrintEventList() // 打印事件链表 
Status ListTraverse(LinkList& L) //遍历链表  
{
LNode* p = L->next;
if (!p)
{
if (!p) {
printf("List is empty.\n");
return ERROR;
}
while (p != NULL)
{
while (p != NULL) {
printf("OccurTime:%d,Event Type:%d\n", p->data.OccurTime, p->data.NType);
p = p->next;
}
@ -280,6 +278,8 @@ Status ListTraverse(LinkList &L) // 遍历链表  
return OK;
}
Status InitQueue(LinkQueue& Q)//链队列的初始化
{
Q.front = Q.rear = (QueuePtr)malloc(sizeof(QNode));
@ -324,8 +324,7 @@ int QueueLength(LinkQueue Q) // 返回队列的长度
{
int count = 0;
QNode* p = Q.front->next;
while (p)
{
while (p) {
p = p->next;
count++;
}
@ -335,9 +334,7 @@ int QueueLength(LinkQueue Q) // 返回队列的长度
Status GetHead(LinkQueue Q, QElemType& e)//获取队头元素
{
if (Q.front == Q.rear)
{
return ERROR;
}
{ return ERROR;}
e = Q.front->next->data;
}
Status QueueEmpty(LinkQueue Q)//判断队列是否为空
@ -352,8 +349,7 @@ void PrintQueue() // 打印队列
{
//打印当前队列  
int i;
for (i = 1; i <= 4; i++)
{
for (i = 1; i <= 4; i++) {
printf("窗口 %d 有 %d 个客户:", i, QueueLength(q[i]));
QueueTraverse(q[i]);
}
@ -362,13 +358,11 @@ void PrintQueue() // 打印队列
Status QueueTraverse(LinkQueue Q)//遍历队列Q  
{
QNode* p = Q.front->next;
if (!p)
{
if (!p) {
printf("--Is empty.\n");
return ERROR;
}
while (p)
{
while (p) {
printf("(到达时刻 %d min 办理业务需要花费 %d min) ", p->data.ArrivalTime, p->data.Duration);
p = p->next;
}

Binary file not shown.
Loading…
Cancel
Save