CS计算机代考程序代写 data structure // This stuff belongs in Stack.h

// This stuff belongs in Stack.h
// so doxygen comments are needed in here.
// Stack class
// Nicola Ritter
// modified smr
//——————————————-

#ifndef MY_STACK
#define MY_STACK

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

#include
#include
using namespace std;

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

template
class Stack
{
public:
Stack () {};
~Stack () {};
bool Push(const T &data);
bool Pop (T &data);
bool Empty () {return m_stack.empty();} // normally body is in the .cpp file but this is a template class, so put it below.
private:
stack m_stack; // most appropriate STL data structure to use for this Type
};

//——————————————-
// It is a template, so we have to put all the code
// in the header file
// If it wasn’t a template, it would go into Stack.cpp
//——————————————-

template
bool Stack::Push(const T &data)
{
bool okay = true;
try
{
m_stack.push(data);
}
catch (…)
{
okay = false;
}

return okay;
}

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

template
bool Stack::Pop(T &data)
{
if (m_stack.size() > 0)
{
data = m_stack.top();

m_stack.pop();
return true;
}
else
{
return false;
}
}

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

#endif