/* * File: mystack.h * ---------------- * * Created by Julie Zelenski on 2/27/08. * */ #ifndef _mystack_h #define _mystack_h #include "genlib.h" #include "vector.h" template class MyStack { public: MyStack(); ~MyStack(); bool isEmpty(); void push(ElemType e); ElemType pop(); private: struct cellT { ElemType val; cellT *next; }; cellT * head; }; #include "mystack.cpp" #endif /* * File: mystack.cpp * ------------------ * * Created by Julie Zelenski on 2/27/08. * */ #include "mystack.h" template MyStack::MyStack() { head = NULL; } template MyStack::~MyStack() { // delete the entire list } template bool MyStack::isEmpty() { return (head == NULL); } template void MyStack::push(ElemType s) { cellT *newCell = new cellT; newCell->val = s; newCell->next = head; head = newCell; } template ElemType MyStack::pop() { if (isEmpty()) Error("pop empty stack"); ElemType top = head->val; cellT *old = head; head = head->next; delete old; return top; }