CS计算机代考程序代写 // Queue.h

// Queue.h

// doxygen comments are needed in this

//
// Queue class
// Version
// Nicola Ritter

// modified smr
// Encapsulates the STL queue, to provide a minimal and complete queue.
//——————————————-

#ifndef MY_QUEUE
#define MY_QUEUE

//——————————————-

#include // uses the STL queue
#include
using namespace std;

//——————————————-

template
class Queue
{
public:
Queue () {};
~Queue () {};
bool Enqueue(const T &data);
bool Dequeue (T &data);
bool Empty () {return m_queue.empty();}
private:
queue m_queue; // uses the STL queue internally
};

//——————————————-
// It is a template, so we have to put all the code
// in the header file
//——————————————-

template // just used T. everyone knows that it is a type parameter. the context is not ambiguous
bool Queue::Enqueue(const DataType &data)
{
bool okay = true;
try
{
m_queue.push(data);
}
catch (…)
{
okay = false;
}

return okay;
}

//——————————————-

template
bool Queue::Dequeue(DataType &data)
{
if (m_queue.size() > 0)
{
data = m_queue.front();
m_queue.pop();
return true;
}
else
{
return false;
}
}

//——————————————-

#endif