- [c++ stack source](https://www.cprogramming.com/tutorial/computersciencetheory/stackcode.
```
/*
| | | Stack Class | | =========================================================== | | This Stack has been implemented with templates to allow it | | to accomodate virtually any data type, and the size of the | | Stack is determined dynamically at runtime. | | | | There is also a new function: peek(), which, given a whole | | number ‘Depth’, returns the Stack element which is ‘Depth’ | | levels from the top. || |
*/
ifndef StackClassH
define StackClassH
include // For error-checking purposes
//————————————————————————- // Main structure of Stack Class: //————————————————————————-
template
inline void Push(const Elem &Item); // Adds Item to the top
inline Elem Pop(void); // Returns Item from the top
inline const Elem &Peek(int Depth) const; // Peek a depth downwards
protected: Elem *Data; // The actual Data array int CurrElemNum; // The current number of elements const int MAX_NUM; // Maximum number of elements };
//————————————————————————- // Implementation of Stack Class: //————————————————————————-
// Stack Constructor function
template
// Stack Destructor function
template
// Push() function
template
Data[CurrElemNum++] = Item; }
// Pop() function
template
return Data[—CurrElemNum]; }
// Peek() function
template
return Data[ CurrElemNum - (Depth + 1) ]; }
endif /StackClassH/
```