📄 customer.cpp
字号:
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
typedef struct{
int arrive;
int treat;
} NODE;
typedef struct node{
NODE data;
node *link;
} LNODE;
LNODE *head=NULL,*tail=NULL;
NODE curr,temp;
char name[120];
FILE *fp;
void len_queue(LNODE *&hpt,LNODE *&tpt,NODE x)
{
LNODE *p=new LNODE;
p->data=x;
p->link=NULL;
if (hpt==NULL)
tpt=hpt=p;
else
{
tpt->link=p;
tpt=p;
}
}
int lde_queue(LNODE *&hpt,LNODE *&tpt,NODE &x)
{
LNODE *p=hpt;
if (hpt==NULL)
return 1;
x=hpt->data;
hpt=hpt->link;
if (hpt==NULL)
tpt=NULL;
delete p;
return 0;
}
void main()
{
int dwait=0,clock=0,wait=0,count=0,have=0,finish;
cout<<"Enter file name:"<<endl;
cin>>name;
if ((fp=fopen(name,"r"))==NULL)
{
cout<<"Can't open file"<<name<<endl;
exit(1);
}
have=fscanf(fp,"%d %d",&temp.arrive,&temp.treat);
do{
if (head==NULL && have==2)
{
dwait+=temp.arrive-clock;
clock=temp.arrive;
len_queue(head,tail,temp);
have=fscanf(fp,"%d %d",&temp.arrive,&temp.treat);
}
count++;
lde_queue(head,tail,curr);
wait+=clock-curr.arrive;
finish=clock+curr.treat;
while (have==2 && temp.arrive<=finish)
{
len_queue(head,tail,temp);
have=fscanf(fp,"%d %d",&temp.arrive,&temp.treat);
}
clock=finish;
}
while (have==2 || head!=NULL);
fclose(fp);
cout<<"结果:接待员等待时间 "<<dwait<<" 顾客平均等待时间 "
<<(float)wait/count<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -