interface of prior. queue

Discussion in 'C++' started by vaclavpich@atlas.cz, Oct 26, 2008.

  1. Guest

    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 _Predicate = Less<_Ty>, // comparator
    class _Container = Array<_Ty> // like std::vector
    >

    class CPriorityQueuePolicy
    {
    _Container c;
    public:
    // common interface :
    _Ty& top();
    void push(const _Ty&);
    void pop();
    };
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2)
    template<
    class _Ty,
    class _Predicate = Less<_Ty>, // comparator
    class _Container = Array<_Ty> // like std::vector
    >

    class CPushPopPolicy : protected CPriorityQueuePolicy<_Ty,
    _Predicate, _Container >
    {
    typedef CPriorityQueuePolicy<_Ty, _Predicate, _Container > base;
    public:
    // common interface :
    void push(const _Ty& val){
    base::push(val);
    }
    _Ty pop(){
    _Ty val = base::top();
    base::pop();
    return val;
    }
    };
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // priority queue :
    template<
    class _Ty,
    class _Predicate = Less<_Ty>, // comparator
    class _Container = Array<_Ty> // like std::vector
    template <class, class, class >class _Policy =
    CPriorityQueuePolicy<_Ty, _Predicate, _Container >
    >

    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.
    , Oct 26, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul L. Du Bois

    Queue.Queue-like class without the busy-wait

    Paul L. Du Bois, Mar 24, 2005, in forum: Python
    Replies:
    29
    Views:
    1,032
    Antoon Pardon
    Apr 4, 2005
  2. Russell Warren

    Is Queue.Queue.queue.clear() thread-safe?

    Russell Warren, Jun 22, 2006, in forum: Python
    Replies:
    4
    Views:
    654
    Russell Warren
    Jun 27, 2006
  3. Kceiw
    Replies:
    3
    Views:
    974
    Jim Langston
    Mar 14, 2006
  4. Gabriel Rossetti
    Replies:
    3
    Views:
    497
    Jerry Hill
    Apr 25, 2008
  5. Kris
    Replies:
    0
    Views:
    433
Loading...

Share This Page