BeloMaximka

Belov_HW_O18

Sep 29th, 2021 (edited)
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. class Stack
  6. {
  7.     enum { EMPTY = -1, FULL = 20 };
  8.     T arr[FULL + 1];
  9.     int top;
  10.  
  11. public:
  12.     Stack();
  13.    
  14.     void push(T val);
  15.     T pop();
  16.     void clear();
  17.    
  18.     bool isEmpty();
  19.     bool isFull();
  20.    
  21.     void showLast();
  22. };
  23.  
  24. template <typename T>
  25. Stack<T>::Stack()
  26. {
  27.     top = EMPTY;
  28. }
  29.  
  30. template <typename T>
  31. void Stack<T>::clear()
  32. {
  33.     top = EMPTY;
  34. }
  35.  
  36. template <typename T>
  37. bool Stack<T>::isEmpty()
  38. {
  39.     return top == EMPTY;
  40. }
  41.  
  42. template <typename T>
  43. bool Stack<T>::isFull()
  44. {
  45.     return top == FULL;
  46. }
  47.  
  48. template<typename T>
  49. inline void Stack<T>::showLast()
  50. {
  51.     cout << arr[top];
  52. }
  53.  
  54. template <typename T>
  55. void Stack<T>::push(T val)
  56. {
  57.     if (!isFull())
  58.         arr[++top] = val;
  59. }
  60.  
  61. template <typename T>
  62. T Stack<T>::pop()
  63. {
  64.     if (!isEmpty())
  65.         return arr[top--];
  66.     else
  67.         return 0;
  68. }
Add Comment
Please, Sign In to add comment