| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 517 人关注过本帖
标题:[求助]下面这段关于优先级队列代码
只看楼主 加入收藏
gundemon
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-1-21
收藏
 问题点数:0 回复次数:0 
[求助]下面这段关于优先级队列代码

#include <iostream.h>
#include <stdlib.h>
const int MaxPQSize=50;

class PQueue
{
private:
int count;
DataType ;pqlist[MaxPQSize];
public:
PQueue(void);
void PQInsert(const DataType,item);
DataType PQDelete(void);
void ClearPQ(void);
int PQEmpty(void) const;
int PQFull(void) const;
int PQLength(void) const;
virtual ~PQueue();
};


void PQueue::PQInsert(const DataType& item)
{
if(count==MaxPQSize)
{
cerr<<"Priority queue overflow!"<<endl;
exit(1);
}
pqlist[count]=item;
count++;
}


DataType PQueue::PQDelete(void)
{
DataType min;
int i,minandex=0;
if(count>0)
{
min=pqlist[0];
for(i=1;i<count;i++)
if(pqlist[i]<min)
{
min=pqlist[i];
minindex=i;
}
pqlist[minindex]=pqlist[count-1];
count--;
}
else
{
cerr<<"Deleting from an empty pqueue!"<<endl;
exit(1);
}
return min;
}

搜索更多相关主题的帖子: 队列 代码 
2007-01-21 17:47
快速回复:[求助]下面这段关于优先级队列代码
数据加载中...
 
   



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

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