#ifndef LINKEDSTACK_H #define LINKEDSTACK_H #include "340.h" #include "SinglyLinkedList.h" template class linkedStack: public SinglyLinkedList { public: linkedStack() {}; virtual ~linkedStack() {}; bool isEmptyStack(); bool isFullStack(); void push(const T& newItem); nodeSLL * top(); void pop(); protected: int count; }; /**************************************************************** FUNCTION: isEmptyStack() ARGUMENTS: none RETURNS: bool - if true'false empty NOTES: returns true if empty false if full ****************************************************************/ template bool linkedStack::isEmptyStack() { return SinglyLinkedList::isEmpty(); } /**************************************************************** FUNCTION: isFullStack() ARGUMENTS: none RETURNS: bool - true/false NOTES: returns true if full ****************************************************************/ template bool linkedStack::isFullStack() { if (count < 10) return false; else return true; } /**************************************************************** FUNCTION: push() ARGUMENTS: newElment RETURNS: none NOTES: this adds a new element to the list ****************************************************************/ template void linkedStack::push(const T& newElement) { if (isFullStack() == false) { SinglyLinkedList::addToHead(newElement); count++; } else cout << "Stack Overflow...\n"; } /**************************************************************** FUNCTION: top() ARGUMENTS: none RETURNS: nodeSLL * NOTES: returns the node at head of list ****************************************************************/ template nodeSLL * linkedStack::top() { return SinglyLinkedList::getHead(); } /**************************************************************** FUNCTION: pop() ARGUMENTS: none RETURNS: none NOTES: removes the top node in the head position of list ****************************************************************/ template void linkedStack::pop() { if (isEmptyStack() == false) { CourseInfo temp = top()->info; SinglyLinkedList::deleteNode(temp); count--; } else cout << "Stack Underflow...\n"; } #endif // END IF LINKEDSTACK.H