my priority queue

V

vaclavpich

Hi all
I want to now your opinion on my priority queue. I know stl has one
very useful but I couldn't use stl. Code below shows the main part of
implementation :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 1) class interface like std::priority_queue
template<
class _Ty,
class StlPriorityQueuePolicy
{
_Container m_container;
public:
// common interface
_Ty& top();
void pop();
push(const _Ty& val);
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 2) class interface only pop and push
emplate<
class _Ty,
class PushpopPriorityQueuePolicy : protected
StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
{
typedef StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
base;
public:
// common interface
_Ty pop(){
if(base::is_empty()) throw exception;
_Ty val = base::top();
base::pop();
return val;
};
push(const _Ty& val){
base::push(val);
}
};

emplate<
class _Ty,
class _Predicate = Less<_Ty>,
class PriorityQueuePolicy : public _Policy<_Ty, _Predicate,
_Container> {};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Maybe it is too compliceted. I like the second policy
(PushpopPriorityQueuePolicy) but it has one disadvantage. Pop method
has to create new value before the value is poped from priority queue
and returned.

Can you tell me your opinion.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top