本人菜鸟 初学数据结构(C++) 有个源程序少头文件
#include"iostream.h"#include"stdlib.h"
#include"genQueue.h"
int option(int percents[])
{
register int i=0,choice=rand()%100+1,perc;
for(perc=percents[0];perc<choice;perc+=percents[i+1],i++);
return i;
}
void main()
{
int arrivals[]={15,20,25,10,30};
int service[]={0,0,0,10,5,10,10,0,15,25,10,15};
int clerks[]={0,0,0,0},numofclerks=sizeof(clerks)/sizeof(int);
int customers,t,i,numofminutes=100,x;
double maxwait=0.0,currwait=0.0,thereisline=0.0;
Queue<int>simulQ;
cout.precision(2)'
for(t=1;t<=numofminutes;t++)
{
cout<<"t="<<t;
for(i=0;i<numofclerks;i++)
if(clerks[i]<60)
clerks[i]=0;
else clerks[i]-=60;
customers=optiom(arrivals);
for(i=0;i<customers;i++)
{
x=option(service)*10;
simulQ.Enqueue(x);
currWait+=x;
}
for(i=0;i<numOfClerks&&!simulQ.isEmpty();)
if(clerks[i]<60){
x=simulQ.Dequeue();
clerks[i]+=x;
currWait-=x;
}
else i++;
if(!simulQ.isEmpty()){
thereIsLine++;
cout<<"wait="<<currWait/60.0;
if(maxWait<currWait)
maxWait=currWait;
}
else cuot<<"wait=0;";
}
cout<<"\nFor"<<numOfClerks<<"clerks,there was a line"
<<thereIsLine/numOfMinutes*100.0<<"% of the time;\n"
<<"maximum wait time was "<<maxWait/60.0<<"min.";}
哪位高手能帮忙加个genQueue.h 谢谢啦~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~