#include <iostream>
using namespace std;
struct Node {
int data;
Node* pNext;
};
struct MyQueue {
Node* pHead = nullptr;
Node* pTail = nullptr;
void enqueue(Node* pNew);
Node* dequeue();
};
int main() {
// Declaration
MyQueue mQueue;
// Enqueue operation
{
Node* mData = new Node;
mData->data = 100000;
mData->pNext = nullptr;
mQueue.enqueue(mData);
}
// Dequeue operation
{
Node* mData = mQueue.dequeue();
cout<<mData->data;
}
return 0;
}
void MyQueue::enqueue(Node* pNew) {
if(!pHead) {
pHead = pNew;
pTail = pNew;
pHead->pNext = nullptr;
} else {
pTail->pNext = pNew;
pTail = pTail->pNext;
}
}
Node* MyQueue::dequeue() {
if(!pHead) return nullptr;
Node* tmp = pHead;
pHead = pHead->pNext;
if(!pHead) pTail = nullptr;
return tmp;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IE5vZGUgewoJaW50IGRhdGE7CglOb2RlKiBwTmV4dDsKfTsKCnN0cnVjdCBNeVF1ZXVlIHsKICAgIE5vZGUqIHBIZWFkID0gbnVsbHB0cjsKICAgIE5vZGUqIHBUYWlsID0gbnVsbHB0cjsKICAgIAogICAgdm9pZCBlbnF1ZXVlKE5vZGUqIHBOZXcpOwogICAgTm9kZSogZGVxdWV1ZSgpOwp9OwoKaW50IG1haW4oKSB7CgkKCS8vIERlY2xhcmF0aW9uCglNeVF1ZXVlIG1RdWV1ZTsKCQoJLy8gRW5xdWV1ZSBvcGVyYXRpb24KCXsKCQlOb2RlKiBtRGF0YSA9IG5ldyBOb2RlOwoJCW1EYXRhLT5kYXRhID0gMTAwMDAwOwoJCW1EYXRhLT5wTmV4dCA9IG51bGxwdHI7CgkJbVF1ZXVlLmVucXVldWUobURhdGEpOwoJfQoJCgkvLyBEZXF1ZXVlIG9wZXJhdGlvbgoJewoJCU5vZGUqIG1EYXRhID0gbVF1ZXVlLmRlcXVldWUoKTsKCQljb3V0PDxtRGF0YS0+ZGF0YTsKCX0KCQ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