Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <typename T>
- class Stack
- {
- enum { EMPTY = -1, FULL = 20 };
- T arr[FULL + 1];
- int top;
- public:
- Stack();
- void push(T val);
- T pop();
- void clear();
- bool isEmpty();
- bool isFull();
- void showLast();
- };
- template <typename T>
- Stack<T>::Stack()
- {
- top = EMPTY;
- }
- template <typename T>
- void Stack<T>::clear()
- {
- top = EMPTY;
- }
- template <typename T>
- bool Stack<T>::isEmpty()
- {
- return top == EMPTY;
- }
- template <typename T>
- bool Stack<T>::isFull()
- {
- return top == FULL;
- }
- template<typename T>
- inline void Stack<T>::showLast()
- {
- cout << arr[top];
- }
- template <typename T>
- void Stack<T>::push(T val)
- {
- if (!isFull())
- arr[++top] = val;
- }
- template <typename T>
- T Stack<T>::pop()
- {
- if (!isEmpty())
- return arr[top--];
- else
- return 0;
- }
Add Comment
Please, Sign In to add comment