smart_stack - #ifndef SMART_STACK_H #define SMART_STACK_H...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#ifndef SMART_STACK_H #define SMART_STACK_H #include <iostream> #include <stdexcept> #include <string> #include <sstream> using namespace std; namespace csci180 { /** A stack implementation based upon use of a linked list. * Elements are inserted and removed according to the last-in * first-out principle. * * This implementation is based on that given pages 180-181 * of our text, but it has been adjusted to suit my tastes. */ template <typename Object> class SmartStack { protected: struct Node { // a node in the stack Object element; // element Node* next; // next pointer int ref_count; // reference counter Node(const Object& e = Object(), Node* n = NULL, int ref = 0) : element(e), next(n), ref_count(ref) { SmartStack::total++; // please leave this command here } ~Node() { SmartStack::total--; // please leave this command here } }; private: Node* tp; // pointer to stack top int sz; // number of items in stack public: /** Standard constructor creates an empty stack. */ SmartStack() : tp(NULL), sz(0) { }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

smart_stack - #ifndef SMART_STACK_H #define SMART_STACK_H...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online