//my_stack.cpp
#include"MyStack.h"
#include<iostream>
using namespace std;
template<class Stack_Entry>
MyStack<Stack_Entry>::MyStack()
{
count = 0;
}
template<class Stack_Entry>
Error_Code MyStack<Stack_Entry>::pop()
{
if (count == 0)return underflow;
else count--;
return success;
}
template<class Stack_Entry>
Error_Code MyStack<Stack_Entry>::push(const Stack_Entry & item)
{
if (count == Max)return overflow;
content[count++] = item;
return success;
}
template<class Stack_Entry>
Error_Code MyStack<Stack_Entry>::top(Stack_Entry & item) const
{
if (count == 0)return underflow;
item = content[count - 1];
return success;
}
template<class Stack_Entry>
bool MyStack<Stack_Entry>::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 Stack_Entry>
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];
};