#ifndef __LINKED_LIST_STACK__ #define __LINKED_LIST_STACK__ template class node { public: T data; node* next; node() { next = NULL; } node(T elem) { data = elem; next = NULL; } }; template class LL_Stack { private: node* tos; public: LL_Stack() { tos = NULL; } ~LL_Stack(); void push(const T& elem); T pop(); bool isEmpty() { return (tos == NULL); } bool isFull() { node* tmp = new node; if (tmp == NULL) return true; delete tmp; return false; } }; template void LL_Stack::push(const T& elem) { node* new_node = new node(elem); new_node->next = tos; tos = new_node; } template T LL_Stack::pop() { node* tmp = tos; tos = tos->next; // tmp->next T rlt = tmp->data; if (tmp != NULL) delete tmp; return rlt; } template LL_Stack::~LL_Stack() { node* tmp; while (tos != NULL) { tmp = tos; tos = tos->next; delete tmp; } } #endif