fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Node {
  5. int data;
  6. Node* pNext;
  7. };
  8.  
  9. struct MyStack {
  10. Node* pHead = nullptr;
  11.  
  12. void push(Node* pNew);
  13. Node* pop();
  14. };
  15.  
  16. int main() {
  17.  
  18. // Declaration
  19. MyStack mStack;
  20.  
  21. // Push operation
  22. {
  23. Node* mData = new Node;
  24. mData->data = 100000;
  25. mData->pNext = nullptr;
  26. mStack.push(mData);
  27. }
  28.  
  29. // Pop operation
  30. {
  31. Node* mData = mStack.pop();
  32. cout<<mData->data;
  33. }
  34.  
  35. return 0;
  36. }
  37.  
  38. void MyStack::push(Node* pNew) {
  39. pNew->pNext = pHead;
  40. pHead = pNew;
  41. }
  42.  
  43. Node* MyStack::pop() {
  44. if(!pHead) return pHead;
  45. Node* tmp = pHead;
  46. pHead = pHead->pNext;
  47. return tmp;
  48. }
Success #stdin #stdout 0s 5512KB
stdin
Standard input is empty
stdout
100000