//my_stack.cpp
#include"MyStack.h"
#include
using namespace std;
template
MyStack::MyStack()
{
count = 0;
}
template
Error_Code MyStack::pop()
{
if (count == 0)return underflow;
else count--;
return success;
}
template
Error_Code MyStack::push(const Stack_Entry & item)
{
if (count == Max)return overflow;
content[count++] = item;
return success;
}
template
Error_Code MyStack::top(Stack_Entry & item) const
{
if (count == 0)return underflow;
item = content[count - 1];
return success;
}
template
bool MyStack::empty()
{
if(count>0) return false;
else return true;
}
//My_stack.h
#pragma once
const int Max = 100;
enum Error_Code { success, overflow, underflow };
template
class MyStack
{
public:
MyStack();
Error_Code pop();
Error_Code push(const Stack_Entry &item);
Error_Code top(Stack_Entry &item) const;
bool empty();
private:
int count;
Stack_Entry content[Max];
};