#include
#include
#include
#include
typedefstruct{
intarrive;//到达时间
inttreat;//服务时间
}QNODE;
typedefstructnode{
QNODEdata;
structnode*next;//队列中的元素信息
}LNODE,*QueuePtr;
typedefstruct{//链队列类型
QueuePtrfront;//队头指针
QueuePtrrear;//队尾指针
}LinkQueue;
voidEnQueue(LinkQueue*link,QNODEx)//进队列
{
LNODE*p=(LNODE*)malloc(sizeof(LNODE));
if(p==NULL)exit(0);
p->data=x;
p->next=NULL;
if(link->front==NULL)
{
link->front=p;
link->rear=link->front;
}
else
{
(link->rear)->next=p;
link->rear=p;
}
free(p);
}
voidDeQueue(LinkQueue*link,QNODE*x)//出队列
{
LNODE*p=link->front;
if(link->front==NULL)
exit(0);
link->front=p->next;
*x=p->data;
if(link->front==NULL)
link->rear=NULL;
free(p);
}
intmain()
{
charFname[100];
FILE*fp;
inthave=0,dwaite=0,cwaite=0,count=0,clock=0,finish=0;
QNODEcurr,temp;
LinkQueuelink;
link.front=NULL;
link.rear=NULL;
printf("输入文件名字:");
scanf("%s",Fname);/*输入装客户模拟数据的文件的文件名*/
if((fp=fopen("Fname","r"))==NULL){/*打开数据文件*/
printf("文件打开出错");
exit(0);
}
have=fscanf(fp,"%d%d",&temp.arrive,&temp.treat);
do{//约定每轮循环,处理完一位客户
if(link.front==NULL&&have==2)
{//等待队列为空时
dwaite+=temp.arrive-clock;
clock=temp.arrive;
EnQueue(&link,temp);
have=fscanf(fp,"%d%d",&temp.arrive,&temp.treat);
}
DeQueue(&link,&curr);
count++;
cwaite+=clock-curr.arrive;
finish=clock+curr.treat;
while(have==2&&finish>temp.arrive)
{
EnQueue(&link,temp);
have=fscanf(fp,"%d%d",&temp.arrive,&temp.treat);
}
clock+=temp.treat;
}while(have==2||link.front!=NULL);
printf("务人员的总空闲时间:%d和客户的平均等待时间:%d",dwaite,cwaite/count);
fclose(fp);
return0;
}
分 -->
|