Advertisement
Kwwiker

Stack.cpp

Apr 14th, 2021
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include "Stack.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. Stack::Stack(int size) :
  7.     m_size(size)
  8. {
  9.     m_list = new int[m_size];
  10. }
  11.  
  12. void Stack::push(int elem) {
  13.     m_list[getQuantity()] = elem;
  14.     m_quantity++;
  15. }
  16.  
  17. void Stack::pop() {
  18.     m_list[getQuantity() - 1] = 0;
  19.     m_quantity--;
  20. }
  21.  
  22. int Stack::peek() {
  23.     return m_list[getQuantity() - 1];
  24. }
  25.  
  26. bool Stack::isEmpty() {
  27.     if (getQuantity() == 0) {
  28.         return true;
  29.     }
  30.     return false;
  31. }
  32.  
  33. void Stack::makeEmpty() {
  34.     while (!isEmpty()) {
  35.         pop();
  36.     }
  37. }
  38.  
  39. int Stack::getSize() {
  40.     return m_size;
  41. }
  42.  
  43. int Stack::getQuantity() {
  44.     return m_quantity;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement