Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * [GenStack.h]
- * The (generic) Stack template declaration/specification.
- */
- #ifndef GENSTACK_H
- #define GENSTACK_H
- #include <iostream>
- template <class ItemType>
- class GenStack
- {
- /**
- * Everything under public can be accessed by all other programs or classes.
- */
- public:
- /**
- * Constructor(s):
- */
- GenStack();
- /**
- * Mutators:
- */
- void Push(ItemType);
- /**
- * Accessors:
- */
- ItemType Pop(void);
- /**
- * General Use:
- */
- /**
- * Everything under protected can be accessed only by the class itself or (derived) subclasses,
- * as in the case of inheritance.
- */
- protected:
- /**
- * (Private) DATA MEMBERS/PROPERTIES:
- *
- * Everything under private can only be accessed by the class itself (the code in the
- * implementation file).
- */
- private:
- int top;
- ItemType data[100];
- };
- #endif // GENSTACK_H
- /**
- * The (generic) Stack template definition/implementation.
- */
- template <class ItemType>
- GenStack<ItemType>::GenStack() // (default) constructor
- {
- top = -1;
- }
- template <class ItemType>
- void GenStack<ItemType>::Push(ItemType item) // mutator
- {
- top++;
- data[top] = item;
- }
- template <class ItemType>
- ItemType GenStack<ItemType>::Pop(void) // accessor
- {
- ItemType item(data[top]);
- top--;
- return item;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement