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:riority_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:op();
return val;
};
push(const _Ty& val){
base:ush(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
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:riority_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:op();
return val;
};
push(const _Ty& val){
base:ush(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