实现优先队列的入队运算,部分代码,求完整

hobelove 2012-03-29 03:59:50
实现优先队列的入队运算,部分代码如下。
//链表头文件说明
#ifndef __priorityLinkQueue__
#define __priorityLinkQueue__

//结点定义
#include <assert.h>
template <class ElemType>
struct linkNode
{
int prior;
ElemType data;
linkNode<ElemType> *next;
};

//定义开始
#include <assert.h>
template <class ElemType>
class priorityLinkQueue
{
private:
linkNode<ElemType> *front,*rear;
public:
priorityLinkQueue();//初始化
~priorityLinkQueue();//销毁
bool isEmpty();//判空,空为true
void clear();//清空
ElemType getFrontElem();//取队首
void addElem(ElemType e,int prior);//入队
void deleteElem();//出队
void print();//打印
};

//实现
//初始化
template <class ElemType>
priorityLinkQueue<ElemType>::priorityLinkQueue()
{
front=new linkNode<ElemType>;
rear=front;
front->next=0;
}
//销毁
template <class ElemType>
priorityLinkQueue<ElemType>::~priorityLinkQueue()
{
clear();
delete front;
front=rear=0;
}
//判空,空为true
template <class ElemType>
bool priorityLinkQueue<ElemType>::isEmpty()
{
if(front==rear)
return true;
return false;
}
//清空
template <class ElemType>
void priorityLinkQueue<ElemType>::clear()
{
while(!isEmpty())
deleteElem();
}
//取队首
template <class ElemType>
ElemType priorityLinkQueue<ElemType>::getFrontElem()
{
assert(!isEmpty());
return front->next->data;
}
//入队
template <class ElemType>
void priorityLinkQueue<ElemType>::addElem(ElemType e,int prior)
{
需要实现的部分
}
//出队
template <class ElemType>
void priorityLinkQueue<ElemType>::deleteElem()
{
需要实现的部分
}
//打印
template <class ElemType>
void priorityLinkQueue<ElemType>::print()
{
if(isEmpty())
{
cout<<"空队"<<endl;
return;
}
linkNode<ElemType> *currentNode;
currentNode=front->next;
while(currentNode)
{
cout<<currentNode->prior<<","<<currentNode->data<<" ";
currentNode=currentNode->next;
}
cout<<endl;
}


#endif

//主函数文件的代码如下
int main()
{
priorityLinkQueue<int> Q=priorityLinkQueue<int>();
for(int i=0;i<10;i++)
Q.addElem(i+1,1);
Q.addElem(11,2);
Q.addElem(12,3);
Q.addElem(13,2);
Q.print();
system("pause");
return 0;
}
...全文
251 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chen_1014 2012-03-29
  • 打赏
  • 举报
回复
我也想法克了。
jiang3230 2012-03-29
  • 打赏
  • 举报
回复
你信不信我给你挂了啊,有你这么说话的吗?
hobelove 2012-03-29
  • 打赏
  • 举报
回复
你猜啊,你猜啊
jiang3230 2012-03-29
  • 打赏
  • 举报
回复
你是那个班的学生啊。
hobelove 2012-03-29
  • 打赏
  • 举报
回复
。。。我fuck你妹!给点实际的ok
jiang3230 2012-03-29
  • 打赏
  • 举报
回复
明天我会讲的。

33,006

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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