Kwwiker

StackOnList.cpp

Apr 14th, 2021
656
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "StackOnList.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. void StackOnList::push(int elem) {
  7.     if (head == NULL)
  8.     {
  9.         Node* temp = new Node;
  10.         temp->info = elem;
  11.         temp->next = NULL;
  12.         head = temp;
  13.     }
  14.     else
  15.     {
  16.         Node* temp = new Node;
  17.         temp->info = elem;
  18.         temp->next = head;
  19.         head = temp;
  20.     }
  21.     m_quantity++;
  22. }
  23.  
  24. void StackOnList::pop() {
  25.     head = head->next;
  26.     m_quantity--;
  27. }
  28.  
  29. int StackOnList::peek() {
  30.     return head->info;
  31. }
  32.  
  33. bool StackOnList::isEmpty() {
  34.     if (getQuantity() == 0) {
  35.         return true;
  36.     }
  37.     return false;
  38. }
  39.  
  40. void StackOnList::makeEmpty() {
  41.     while (!isEmpty()) {
  42.         pop();
  43.     }
  44. }
  45.  
  46. int StackOnList::getQuantity() {
  47.     return m_quantity;
  48. }
  49.  
RAW Paste Data