Hollowfires

Untitled

Apr 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #ifndef STACK_H
  2. #define STACK_H
  3. #include <iostream>
  4.  
  5. template <class T>
  6. class StackNode
  7. {
  8. private:
  9. T value;
  10. StackNode<T> *next;
  11.  
  12. public:
  13.  
  14. StackNode(T newItem, StackNode<T> *newNext)
  15. {
  16. value = newItem;
  17. next = newNext;
  18. }
  19.  
  20. StackNode<T> * getNext()
  21. {
  22. return next;
  23. }
  24.  
  25. T getData()
  26. {
  27. return value;
  28. }
  29. };
  30.  
  31. // Stack class
  32. template<class T>
  33. class Stack
  34. {
  35. private:
  36. StackNode<T> * top;
  37.  
  38. public:
  39. Stack();
  40.  
  41. // Push
  42. void push(T newItem);
  43.  
  44. // Peek
  45. T peek();
  46.  
  47. // Pop
  48. T pop();
  49.  
  50. // isEmpty
  51. bool isEmpty();
  52.  
  53. // clear
  54. void clear();
  55.  
  56. // display stack contents
  57. void display();
  58. };
  59. #endif
Advertisement
Add Comment
Please, Sign In to add comment