V
vaclavpich
Hi all,
I needed a priority queue but I couldn't use stl. So I wrote my
priority queue. But I'm not sure that my implementation is good. I
want to know your opinion :
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1)
template<
class _Ty,
class CPriorityQueuePolicy
{
_Container c;
public:
// common interface :
_Ty& top();
void push(const _Ty&);
void pop();
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2)
template<
class _Ty,
class CPushPopPolicy : protected CPriorityQueuePolicy<_Ty,
_Predicate, _Container >
{
typedef CPriorityQueuePolicy<_Ty, _Predicate, _Container > base;
public:
// common interface :
void push(const _Ty& val){
base:ush(val);
}
_Ty pop(){
_Ty val = base::top();
base:op();
return val;
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// priority queue :
template<
class _Ty,
class _Predicate = Less<_Ty>, // comparator
class _Container = Array<_Ty> // like std::vector
class CPriorityQueue : public _Policy<_Ty, _Predicate, _Container> {};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I want to have 2 kinds of priority queue and I can choose the best
interface.
I'm not sure that people can easily use my priority queue.
If you have better idea how to write it please tell me. Or write only
your opinion.
Thanks.
I needed a priority queue but I couldn't use stl. So I wrote my
priority queue. But I'm not sure that my implementation is good. I
want to know your opinion :
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1)
template<
class _Ty,
class CPriorityQueuePolicy
{
_Container c;
public:
// common interface :
_Ty& top();
void push(const _Ty&);
void pop();
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2)
template<
class _Ty,
class CPushPopPolicy : protected CPriorityQueuePolicy<_Ty,
_Predicate, _Container >
{
typedef CPriorityQueuePolicy<_Ty, _Predicate, _Container > base;
public:
// common interface :
void push(const _Ty& val){
base:ush(val);
}
_Ty pop(){
_Ty val = base::top();
base:op();
return val;
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// priority queue :
template<
class _Ty,
class _Predicate = Less<_Ty>, // comparator
class _Container = Array<_Ty> // like std::vector
class CPriorityQueue : public _Policy<_Ty, _Predicate, _Container> {};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I want to have 2 kinds of priority queue and I can choose the best
interface.
I'm not sure that people can easily use my priority queue.
If you have better idea how to write it please tell me. Or write only
your opinion.
Thanks.