| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 680 人关注过本帖
标题:本人菜鸟 初学数据结构(C++) 有个源程序少头文件
只看楼主 加入收藏
huangyan6611
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2009-4-29
结帖率:87.5%
收藏
 问题点数:0 回复次数:5 
本人菜鸟 初学数据结构(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 谢谢啦~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
搜索更多相关主题的帖子: 文件 数据结构 
2009-11-06 09:16
flyingcloude
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:6
帖 子:598
专家分:1512
注 册:2008-1-13
收藏
得分:0 
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;//指向下一个应当移走的队列元素的位置
};



你能学会你想学会的任何东西,这不是你能不能学会的问题,而是你想不想学的问题
2009-11-06 11:42
huangyan6611
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2009-4-29
收藏
得分:0 
怎么老是提示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)
2009-11-06 22:11
flyingcloude
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:6
帖 子:598
专家分:1512
注 册:2008-1-13
收藏
得分:0 
回复 3楼 huangyan6611
类的大括号后是否忘了加分号?

class Queue
{
};

你能学会你想学会的任何东西,这不是你能不能学会的问题,而是你想不想学的问题
2009-11-07 11:38
huangyan6611
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2009-4-29
收藏
得分:0 
加了啊。。。。。。。。。。。
2009-11-11 07:53
灵怯颜
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-10-22
收藏
得分:0 
解决了吗?
2017-10-22 21:45
快速回复:本人菜鸟 初学数据结构(C++) 有个源程序少头文件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016159 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved