Code: Select all
#ifndef STACK_H
#define STACK_H
#include "LinkedList.h"
template<class TemplateItem>
class Stack
{
public:
Stack();
virtual ~Stack();
Stack(const Stack& obj);
Stack& operator=(const Stack& obj);
bool push(TemplateItem);
bool pop();
bool empty();
TemplateItem top();
private:
LinkedList<TemplateItem> mStackList;
};
/****Function definitons****/
template<class TemplateItem>
Stack<TemplateItem>::Stack()
{
}
template<class TemplateItem>
Stack<TemplateItem>::~Stack()
{
}
template<class TemplateItem>
Stack<TemplateItem>& Stack<TemplateItem>::operator=(const Stack& obj)
{
mStackList = obj.mStackList;
return *this;
}
template<class TemplateItem>
Stack<TemplateItem>::Stack(const Stack& obj)
{
mStackList = obj.mStackList;
}
template<class TemplateItem>
bool Stack<TemplateItem>::push(TemplateItem item)
{
return mStackList.insertFirst(item)
}
template<class TemplateItem>
bool Stack<TemplateItem>::pop()
{
return mStackList.removeFirst();
}
template<class TemplateItem>
bool Stack<TemplateItem>::empty()
{
return mStackList.size() > 0;
}
template<class TemplateItem>
TemplateItem Stack<TemplateItem>::top()
{
return mStackList.elementAt(0);
}
#endif