Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. template<typename S>
  2. class Level {
  3. public:
  4. S item;
  5. Level* next;
  6. Level(S it, Level* stk) {
  7. item = it;
  8. next = stk;
  9. }
  10. ~Level() {
  11. delete next;
  12. }
  13. };
  14.  
  15. template<typename T>
  16. class Stack {
  17. public:
  18. Level<T>* top;
  19. Stack() {
  20. top = NULL;
  21. }
  22. void push(T item) {
  23. top = new Level<T>(item, top);
  24. }
  25. T pop() {
  26. T item = top->item;
  27. this->top = top->next;
  28. return item;
  29. }
  30. ~Stack() {
  31. delete top;
  32. }
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement