#include <iostream>
using namespace std;
struct Node {
int data;
Node* pNext;
};
struct MyStack {
Node* pHead = nullptr;
void push(Node* pNew);
Node* pop();
};
int main() {
// Declaration
MyStack mStack;
// Push operation
{
Node* mData = new Node;
mData->data = 100000;
mData->pNext = nullptr;
mStack.push(mData);
}
// Pop operation
{
Node* mData = mStack.pop();
cout<<mData->data;
}
return 0;
}
void MyStack::push(Node* pNew) {
pNew->pNext = pHead;
pHead = pNew;
}
Node* MyStack::pop() {
if(!pHead) return pHead;
Node* tmp = pHead;
pHead = pHead->pNext;
return tmp;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IE5vZGUgewoJaW50IGRhdGE7CglOb2RlKiBwTmV4dDsKfTsKCnN0cnVjdCBNeVN0YWNrIHsKICAgIE5vZGUqIHBIZWFkID0gbnVsbHB0cjsKICAgIAogICAgdm9pZCBwdXNoKE5vZGUqIHBOZXcpOwogICAgTm9kZSogcG9wKCk7Cn07CgppbnQgbWFpbigpIHsKCQoJLy8gRGVjbGFyYXRpb24KCU15U3RhY2sgbVN0YWNrOwoJCgkvLyBQdXNoIG9wZXJhdGlvbgoJewoJCU5vZGUqIG1EYXRhID0gbmV3IE5vZGU7CgkJbURhdGEtPmRhdGEgPSAxMDAwMDA7CgkJbURhdGEtPnBOZXh0ID0gbnVsbHB0cjsKCQltU3RhY2sucHVzaChtRGF0YSk7Cgl9CgkKCS8vIFBvcCBvcGVyYXRpb24KCXsKCQlOb2RlKiBtRGF0YSA9IG1TdGFjay5wb3AoKTsKCQljb3V0PDxtRGF0YS0+ZGF0YTsKCX0KCQoJcmV0dXJuIDA7Cn0KCnZvaWQgTXlTdGFjazo6cHVzaChOb2RlKiBwTmV3KSB7CiAgICBwTmV3LT5wTmV4dCA9IHBIZWFkOwogICAgcEhlYWQgPSBwTmV3Owp9CgpOb2RlKiBNeVN0YWNrOjpwb3AoKSB7CiAgICBpZighcEhlYWQpIHJldHVybiBwSGVhZDsKICAgIE5vZGUqIHRtcCA9IHBIZWFkOwogICAgcEhlYWQgPSBwSGVhZC0+cE5leHQ7CiAgICByZXR1cm4gdG1wOwp9