注册 登录
编程论坛 C++教室

本人菜鸟 初学数据结构(C++) 有个源程序少头文件

huangyan6611 发布于 2009-11-06 09:16, 702 次点击
#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 谢谢啦~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 回复
#2
flyingcloude2009-11-06 11:42
STL中有queue的头文件。

genQueue你可以按照下面这样去实现。

程序代码:
template<class T>
class Queue
{
public:
        Queue(unsigned int size);
        Queue(const Queue& other);
        void Enqueue(T x); //进队列
        T Dequeue();    //出队列
        bool isEmpty(); //判对队列是否为空
private:
        const unsigned int max;
        T *data;
        int nextSlot; //指向下一个元素插入的位置
        int nextUse;//指向下一个应当移走的队列元素的位置
};


#3
huangyan66112009-11-06 22:11
怎么老是提示genqueue.h中少";"啊



--------------------Configuration: wufei - Win32 Debug--------------------
Compiling...
main.cpp
d:\program files\microsoft visual studio\myprojects\wufei\genqueue.h(16) : error C2143: syntax error : missing ';' before '<position>
'
d:\program files\microsoft visual studio\myprojects\wufei\genqueue.h(16) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

wufei.exe - 1 error(s), 0 warning(s)
#4
flyingcloude2009-11-07 11:38
回复 3楼 huangyan6611
类的大括号后是否忘了加分号?

class Queue
{
};
#5
huangyan66112009-11-11 07:53
加了啊。。。。。。。。。。。
#6
灵怯颜2017-10-22 21:45
解决了吗?
1