请达人帮我看看这段程序的问题,高分

code菜鸟newbee 2005-05-05 09:32:26
rt
#include <iostream>
#include "stdlib.h"
#include "time.h"
#define Counter 2
#define null 0
#define CloseTime 480
using namespace std;
int TotalTime,CustomerNum;

struct Event
{
int Occurtime;
int NType;
Event *next;
};

struct QueueElem
{
int Arrival;
int duration;
QueueElem *next;
};

struct QueueList
{
QueueElem *front;
QueueElem *rear;
int Count;
};

typedef Event* EventList;
typedef QueueList* QuListArray;

void InitQuList(QueueList &Queue)
{
Queue.front=new QueueElem;
Queue.rear=Queue.front;
Queue.front->Arrival=0;
Queue.front->duration=0;
Queue.front->next=null;
Queue.Count=0;
}


void GetHead(QueueList &Queue,QueueElem &en)
{
en=*Queue.front->next;
en.next=null;
}


void EnQueue(QueueList &Queue,QueueElem &en)
{
QueueElem *P=new QueueElem;
*P=en;
Queue.rear->next=P;
Queue.rear=P;
Queue.Count++;
}

void DeQueue(QueueList &Queue,int &e)
{
if(Queue.front!=Queue.rear)
{
QueueElem *P=Queue.front->next;
Queue.front->next=P->next;
if(Queue.rear==P)
{
Queue.rear=Queue.front;
}
e=P->Arrival;
delete P;
Queue.Count--;
}
}

void InitEVList(EventList &EV)
{
EV=new Event;
EV->NType=0;
EV->Occurtime=0;
EV->next=null;
}


int cmp(Event a,Event b)
{
if(a.Occurtime>b.Occurtime)
{
return 1;
}
else if(a.Occurtime<b.Occurtime)
{
return -1;
}
else
{
return 0;
}
}

void InsertEvent(EventList &EV,Event &en,int(*cmp)(Event,Event))
{
Event *P,*Q;
Event *Temp=new Event;
*Temp=en;
P=Q=EV;
P=P->next;
if(P!=null)
{
while(P!=null)
{
if(cmp(*P,en)==-1)
{
P=P->next;
Q=Q->next;
}
else if(cmp(*P,en)==1)
{
Temp->next=P;
Q->next=Temp;
return;
}
else
{
P->next=Temp;
return;
}
}
Q->next=Temp;
Temp->next=P;
}
else
{
Q->next=Temp;
Temp->next=null;
}

}






void OpenForDay(EventList &EV,QuListArray &QuPoint)
{
Event *temp;
temp=new Event;
TotalTime=0;
CustomerNum=0;

temp->NType=0;
temp->Occurtime=0;
EV->next=temp;
temp->next=null;



}

int Minimum(QuListArray &QuPoint)
{
int i=0,j=0,Min=QuPoint[0].Count;
for(i;i<Counter;i++)
{
if(Min>QuPoint[i].Count)
{
Min=QuPoint[i].Count;
j=i;
}
}
return j;
}



void CustomerArrived(EventList &EV,Event &en,QuListArray &QuPoint)
{

int i,j,t,Min;
srand(time(NULL));
i=1+rand()%30;//客户办理业务所要时间
j=1+rand()%5;
t=en.Occurtime+j;//下个客户到达时间
Event Temp={t,0,null};
if(t<CloseTime)
{
CustomerNum++;
InsertEvent(EV,Temp,cmp);
}

Min=Minimum(QuPoint);
QueueElem temp={en.Occurtime,i,null};

EnQueue(QuPoint[Min],temp);
if(QuPoint[Min].Count==1)
{
Event Temp={en.Occurtime+i,Min+1,null};
InsertEvent(EV,Temp,cmp);
}
}
int EmptyQueue(QueueList &Queue)
{
if(Queue.Count==0)
{
return 1;
}
else
{
return 0;
}
}

void CustomerDepartment(EventList &EV,Event &en,QuListArray &QuPoint)
{
int i=en.NType,arrival;
DeQueue(QuPoint[i-1],arrival);
TotalTime=TotalTime+en.Occurtime-arrival;
if(!EmptyQueue(QuPoint[i-1]))
{
QueueElem En;
GetHead(QuPoint[i-1],En);
Event temp={En.duration+en.Occurtime,i,null};
InsertEvent(EV,temp,cmp);
}


}

int EmptyEV(EventList &EV)
{
if(EV->next==null)
{
return 1;
}
else
{
return 0;
}
}



void DeFirstEV(EventList &EV,Event &en)
{
Event *temp;
temp=EV->next;
EV->next=temp->next;
en=*temp;
delete temp;
}


void main()
{

Event en;
EventList EV;
InitEVList(EV);
QueueList Q[Counter];
QuListArray QuPoint;
QuPoint=Q;
for(int i=0;i<Counter;i++)
{
InitQuList(QuPoint[i]);
}

OpenForDay(EV,QuPoint);

while(!EmptyEV(EV))
{
DeFirstEV(EV,en);
if(en.NType==0)
{
CustomerArrived(EV,en,QuPoint);
}
else
{
CustomerDepartment(EV,en,QuPoint);
}
}

cout<<TotalTime/CustomerNum<<endl;

}






















...全文
281 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
code菜鸟newbee 2005-05-25
  • 打赏
  • 举报
回复
声明一下哈,是朋友拿我的号发的,他没有可用分
现在他人不晓得到哪里去了,我也不晓得他这程序是什么的。c++我都不懂
大概是个银行排队的东东
还是把分散了吧
sun428 2005-05-07
  • 打赏
  • 举报
回复
好长啊……
delhe 2005-05-07
  • 打赏
  • 举报
回复
双向链对列吧?
a84913434 2005-05-07
  • 打赏
  • 举报
回复
.....................
CloudOfFly 2005-05-07
  • 打赏
  • 举报
回复
晕了
jecray 2005-05-07
  • 打赏
  • 举报
回复
莫名其妙..
zharry 2005-05-07
  • 打赏
  • 举报
回复
把问题讲清楚???
yangkun110 2005-05-07
  • 打赏
  • 举报
回复
眼花啊
cunsh 2005-05-07
  • 打赏
  • 举报
回复
似乎是事件驱动那儿讲的一个例子.
但是太长了啊.n长.
ZHUSHAOWEI 2005-05-07
  • 打赏
  • 举报
回复
给多点相关的信息嘛!
aaww110 2005-05-06
  • 打赏
  • 举报
回复
注释都没有???
眼花, 何况你还不指明你程序干什么,问题有哪些?? 更眼花~~~~
楼主问问题要厚道的哈...
flyingdancing2005 2005-05-06
  • 打赏
  • 举报
回复
............
plovej 2005-05-06
  • 打赏
  • 举报
回复
太长了,难看啊
coolvc2002 2005-05-06
  • 打赏
  • 举报
回复

是一个双向队列的代码吧,主要是用来处理客户排队的东西罗!
个人觉得应该用c++来封装,不然的话,可维护性不是很高的。
oyljerry 2005-05-05
  • 打赏
  • 举报
回复
讲一下代码有什么问题
guyaguya 2005-05-05
  • 打赏
  • 举报
回复
?
yuhjnm_20001 2005-05-05
  • 打赏
  • 举报
回复
mark
llf_hust 2005-05-05
  • 打赏
  • 举报
回复
说一下这段程序是干什么的呀
太长了
flying_dancing 2005-05-05
  • 打赏
  • 举报
回复
人跑路了
ericqxg007 2005-05-05
  • 打赏
  • 举报
回复
干什么
加载更多回复(8)

64,318

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧