Advertisement
Guest User

stack

a guest
Oct 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. /**
  2.  * sNodeStack.hpp
  3.  *
  4.  * Copyright 2018 Andrew Hughes (ahughes6@buffalo.edu)
  5.  *
  6.  * This work is licensed under the Creative Commons
  7.  * Attribution-NonCommercial-ShareAlike 4.0 International License.
  8.  * To view a copy of this license, visit
  9.  * http://creativecommons.org/licenses/by-nc-sa/4.0/.
  10.  *
  11.  * Submission by
  12.  * UBIT:
  13.  * Person#:
  14.  */
  15.  
  16. #ifndef _SNODESTACK_HPP_
  17. #define _SNODESTACK_HPP_
  18.  
  19. #include "sNode.hpp"
  20.  
  21. template<typename T>
  22. class sNodeStack {
  23. public:
  24.     // Do not change visibility or type of head.
  25.     cse250::sNode<T>* head;
  26.     cse250::sNode<T>* tail;
  27.     // Define necessary stack functionality.
  28.  
  29.     sNodeStack(){
  30.         head = nullptr;
  31.     }
  32.  
  33.     ~sNodeStack(){
  34.  
  35.     }
  36.  
  37.     void push(const T& value) {
  38.         //Lecture 9/28
  39.         cse250::sNode<T>* temp = new cse250::sNode<T>;
  40.         temp->value = value;
  41.         temp->next = head;
  42.         head = temp;
  43.  
  44.     }
  45.  
  46.     T& top(){
  47.         return head->value;
  48.     }
  49.  
  50.     void pop(){
  51.         cse250::sNode<T>* temp = head;
  52.         head = head->next;
  53.         delete temp;
  54.     }
  55.  
  56.     bool empty() const{
  57.         if(head == nullptr){
  58.             return true;
  59.         }
  60.         return false;
  61.     }
  62.  
  63. };//sNodeStack
  64.  
  65. #endif //_SNODESTACK_HPP_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement