Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "linkedListStack.h"
  4. using namespace std;
  5.  
  6. //constructor implementation
  7. linkedListStack::linkedListStack():top(NULL) {
  8.  
  9. void push(int v)
  10. {
  11. listNode *newNode = new listNode;
  12. newNode->value = v;
  13. newNode->next = top;
  14. top = newNode;
  15. cout<<"Pushed "<< newNode->data << endl << newNode->next << endl;
  16.  
  17. }
  18.  
  19. int pop()
  20. {
  21. if (isEmpty())
  22. {
  23. throw string("Stack is empty");
  24. }
  25. listNode *newNode = new listNode;
  26. newNode = top;
  27. top = newNode->next;
  28. cout<<"Popped "<< newNode->data << endl;
  29. delete newNode;
  30.  
  31.  
  32. };
  33.  
  34.  
  35.  
  36.  
  37. bool isEmpty()
  38. {
  39. return (top == NULL);
  40.  
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. }
  48.  
  49.  
  50.  
  51. //destructor
  52. linkedListStack::~linkedListStack() {
  53.  
  54.  
  55.  
  56. cout << "Stack has been deleted" << endl;
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement