I've been given an assignment to make 3 template classes for stacks. The 1st is for a static stack. The 2nd for dynamic stacks. The 3rd is for linked lists. The code for the first one is below. I would appreciate someone going over it and seeing if my thinking and code were right. Thank You
#ifndef Main_Savitch_Stack1_H
#define Main_Savitch_Stack1_H
#include <cstdlib>
namespace main_savitch_stack1_H
{
template <class Item>
class stack
{
public:
typedef std::size_t size_type;
typedef Item value_type;
static const size_type CAPACITY = 30;
stack(){used=0;}
void push(const Item& entry);
void pop( );
bool empty( ) const { return (used == 0); }
size_type size( ) const { return used; }
Item top( ) const;
private:
Item data[CAPACITY];
size_type used;
};
}
//IMPLEMENTATION BEGINS HERE
#include <cassert>
template <class Item>
void stack<item>:ush(const item& entry)
{
assert (size())<capacity);
data[used]=entry;
++used;
}
template <class Item>
void stack<item>:op()
{
assert (!empty());
if (!empty())
--used;
}
template <class item>
item stack<item>::top()
{
assert(!empty());
return data[used-1]
}