V
vaclavpich
Hi all,
I want to now your opinion on interface of my priority_queue. I now
std has very good a priority_queue. But I couldn't use std. So I had
to write my.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// example :
// this class has the same interface like std:riority_queue
template<
class _Ty, // type to store
class StlPriorityQueuePolicy
{
_Container m_Cont;
public:
// common interface :
push(const _Ty& val)
_Ty& top();
void pop();
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class has only push and pop methods
template<
class _Ty, // type to store
class PushPopPriorityQueuePolicy : protected
StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
{
typedef StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
base;
public:
// common interface :
push(const _Ty& val){
base:ush(val);
}
_Ty pop(){
if(base::is_empty()) throw exception;
_Ty elem = base::top();
base:op();
return elem;
}
};
template<
class _Ty,
class _Predicate = Less<_Ty>,
class _Container = Array<_Ty>,
class PriorityQueue : public _PriorityQueuePolicy< _Ty, _Predicate,
_Container> {};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I'm not sure that this is very clever interface. Maybe is complicated
to use.A lot of people know how to use std:riority_queue.It is good
but I prefer the second policy. I know about one disadvantige of
PushPopPriorityQueuePolicy. Pop method has to create an element which
return. In the other hand PushPopPriorityQueuePolicy is very simple to
use.
If you know better way to implement priority queue please can you show
me how.
Thank you.
I want to now your opinion on interface of my priority_queue. I now
std has very good a priority_queue. But I couldn't use std. So I had
to write my.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// example :
// this class has the same interface like std:riority_queue
template<
class _Ty, // type to store
class StlPriorityQueuePolicy
{
_Container m_Cont;
public:
// common interface :
push(const _Ty& val)
_Ty& top();
void pop();
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class has only push and pop methods
template<
class _Ty, // type to store
class PushPopPriorityQueuePolicy : protected
StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
{
typedef StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
base;
public:
// common interface :
push(const _Ty& val){
base:ush(val);
}
_Ty pop(){
if(base::is_empty()) throw exception;
_Ty elem = base::top();
base:op();
return elem;
}
};
template<
class _Ty,
class _Predicate = Less<_Ty>,
class _Container = Array<_Ty>,
class PriorityQueue : public _PriorityQueuePolicy< _Ty, _Predicate,
_Container> {};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I'm not sure that this is very clever interface. Maybe is complicated
to use.A lot of people know how to use std:riority_queue.It is good
but I prefer the second policy. I know about one disadvantige of
PushPopPriorityQueuePolicy. Pop method has to create an element which
return. In the other hand PushPopPriorityQueuePolicy is very simple to
use.
If you know better way to implement priority queue please can you show
me how.
Thank you.