Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
amma2
struct node { int key; int value; node* next; node* prev; }; class Cache { map<int, node*> m; node* head; node* tail; public: void put(int key, int value) { tail->next = new node(key, value); m[key] = tail->next; node* tmp = tail; tail = tail->next; tail->prev = tmp; } int get(int key) { } void remove(int key) { if (m.find(key) != m.end()) { if (m[key] == head) { node* tmp = head; head = head->next; delete tmp; } else if (m[key] == tail) { node* tmp = tail; tail = tail->prev; delete tmp; } else { node* tmp = m[key]; tmp->next->prev = tmp->prev; tmp->prev->next = tmp->next; delete m[key]; } m.erase(key); } } };
run
|
edit
|
history
|
help
0
Make Bin Tree
Mirror a binary tree
Best time to buy and sell stocks
Using C's sprinf() Function to Format Output String
printAllPathsInMatrix
decode
Dar
Float
Double_wrapper gcc
Primality test Fermat primality test