I'm trying to implement a queue where I'm not allowed to change the header file definition, which looks like this:
class PQueue
{
private:
struct Node
{
EType Item;
unsigned Priority;
unsigned Identifier;
Node * Pred;
Node * Succ;
};
Node * Head; // Pointer to head of chain (front)
Node * Tail; // Pointer to tail of chain (back)
public:
// Initialize pqueue to empty
//
PQueue();
// De-initialize pqueue
//
~PQueue();
// Re-initialize pqueue to empty
//
void reset();
// Initialize pqueue using existing pqueue
//
PQueue( const PQueue<EType>& );
// Assign into pqueue from other pqueue
//
PQueue<EType>& operator=( const PQueue<EType>& );
// Display attributes and contents of pqueue
// (from front to back, or back to front)
//
void display( ostream&, Direction ) const;
// Return number of items in pqueue
//
unsigned length() const;
// Return copy of item at front of pqueue (unless pqueue is empty)
//
bool front( EType& ) const;
// Return copy of item at back of pqueue (unless pqueue is empty)
//
bool back( EType& ) const;
// Insert one item (with specified priority) into pqueue (if possible)
//
bool put( const EType&, unsigned );
// Remove item with highest priority from pqueue (unless pqueue is empty)
//
bool get( EType& );
// Discard item with specified identifier from pqueue (if possible)
//
bool discard( unsigned );
};
So far I have these constructors and destructors:
template <typename EType> PQueue::PQueue() {
Head->Pred = NULL;
Tail->Succ = NULL;
Tail->Pred=Head;
Head->Succ=Tail;
}
template <typename EType> PQueue::~PQueue() {
reset();
delete Head;
Head = NULL;
delete Tail;
Tail = NULL;
}
Now I am stuck on the put()
, I have no idea where to start, any help?