-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLRU.cpp
More file actions
63 lines (53 loc) · 1001 Bytes
/
LRU.cpp
File metadata and controls
63 lines (53 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <unordered_map>
#include <list>
using namespace std;
class LRU{
int capacity;
class Node{
public:
int key ;
int value;
Node* head;
Node* tail;
Node(int k ,int v){
key =k;
value = v;
head = NULL;
prev = NULL;
}
};
unordered_map<int,Node*>m;
Node* head;
Node* tail;
void addnode(Node* node){
node->next = head;
head->prev = node;
head = node;
}
void removenode(Node* node){
Node* prev = node->prev;
Node* next = node->next;
prev->next = next;
next->prev = prev;
}
void movehead(Node* node){
removenode(node);
addnode(node);
}
Node* poptail(){
Node * prev = tail->prev;
removenode(tail);
return prev;
}
public:
LRU(int cap){
capacity = cap;
head = new Node(0,0);
tail = new Node(0,0);
head->next = tail;
tail->prev = head;
}
int get(int key){
}
};