#include <iostream>
using namespace std;
#include <iostream>
class LinkedList{
// Struct inside the class LinkedList
// This is one node which is not needed by the caller. It is just
// for internal work.
struct Node {
int x;
Node *next;
};
// public member
public:
// constructor
/* constexpr */ LinkedList() : head(nullptr) {
}
// This prepends a new value at the beginning of the list
void addValue(int val){
Node *n = new Node(); // create new Node
n->x = val; // set value
n->next = head; // make the node point to the next node.
// If the list is empty, this is NULL, so the end of the list --> OK
head = n; // last but not least, make the head point at the new node.
}
// returns the first element in the list and deletes the Node.
// caution, no error-checking here!
int popValue(){
Node *n = head;
int ret = n->x;
head = head->next;
delete n;
return ret;
}
// private member
private:
Node *head; // this is the private member variable. It is just a pointer to the first Node
};
extern LinkedList list;
int my_crazy_variable = ([]{ list.addValue(10); return 0; })();
LinkedList list;
int main() {
using namespace std;
cout << my_crazy_variable << endl;
cout << list.popValue() << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgTGlua2VkTGlzdHsKICAgIC8vIFN0cnVjdCBpbnNpZGUgdGhlIGNsYXNzIExpbmtlZExpc3QKICAgIC8vIFRoaXMgaXMgb25lIG5vZGUgd2hpY2ggaXMgbm90IG5lZWRlZCBieSB0aGUgY2FsbGVyLiBJdCBpcyBqdXN0CiAgICAvLyBmb3IgaW50ZXJuYWwgd29yay4KICAgIHN0cnVjdCBOb2RlIHsKICAgICAgICBpbnQgeDsKICAgICAgICBOb2RlICpuZXh0OwogICAgfTsKCi8vIHB1YmxpYyBtZW1iZXIKcHVibGljOgogICAgLy8gY29uc3RydWN0b3IKICAgIC8qIGNvbnN0ZXhwciAqLyBMaW5rZWRMaXN0KCkgOiBoZWFkKG51bGxwdHIpIHsKICAgIH0KCiAgICAvLyBUaGlzIHByZXBlbmRzIGEgbmV3IHZhbHVlIGF0IHRoZSBiZWdpbm5pbmcgb2YgdGhlIGxpc3QKICAgIHZvaWQgYWRk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