欢迎来到天天文库
浏览记录
ID:14318256
大小:43.50 KB
页数:11页
时间:2018-07-27
《单向链队列中的优先队列》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、单向链队列中的优先队列//===================================================================================================//单向链队列中的优先队列//===================================================================================================#includeusingnamespacestd;//-------------
2、--------------------------------------------------------------------------------------templateclassListQueue;//---------------------------------------------------------------------------------------------------templateclassListQueueNode{public:friendclassListQu
3、eue;friendostream&operator<<(ostream&o,constListQueue&x);ListQueueNode(T&value,intpri);booloperator==(constListQueueNode&p){returnelement==p.element&&prior==p.prior;}booloperator!=(constListQueueNode&p){returnelement!=p.element&&prior!=p.prior;}booloperator>(constL
4、istQueueNode&p){returnprior>p.prior;}booloperator<=(constListQueueNode&p){returnprior<=p.prior;}booloperator=(constListQueueNode&p){element=p.element;prior=p.prior;link=NULL;return1;}~ListQueueNode(){};private:Telement;intprior;ListQueueNode*link;};//--------------
5、---------------------------------------------------------------------------------------templateListQueueNode::ListQueueNode(T&value,intpri){element=value;prior=pri;link=NULL;}//-----------------------------------------------------------------------------------------
6、--------------templateclassListQueue{public:ListQueue();ListQueue(T&x,intpri);~ListQueue();voidInQueue(T&x,intpri);voidDeQueue(T&x);boolEmpty()const;intLength()const;voidSetpri(constT&element,intpri);intFind(T&element,intpri);intFindall(T&element,intpri,int*parameter);
7、voidDisplay()const;voidtravel(void(*Fun)(T&x));voidClear();friendostream&operator<<(ostream&o,constListQueue&x){if(x.length==0)returno<<"队列中无元素."<*current=x.head;current!=NULL;current=current->link)o<element<<""<prior<8、;}returno;}private:intlength;ListQueueNode*head;};//------
8、;}returno;}private:intlength;ListQueueNode*head;};//------
此文档下载收益归作者所有