Least Recently Used

구현

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <list>
using namespace std;

int main() {
list<int> cache;
int item;
int cacheSize = 3; //Cache Size
int count = 0; //Cache Miss 횟수
while(true){
cin >> item;
if(cin.fail()) break;
cache.remove(item);
if(cache.size() < cacheSize) cache.push_back(item);
else{
cout << cache.front() << endl; //교체가 일어난 item 출력
cache.pop_front();
cache.push_back(item);
cache++;
}
}
if(count == 0) cout << 0 << endl; //Cache Miss가 0이면 0 출력
return 0;
}
Author

Daeyoung Kim

Posted on

2018-09-28

Updated on

2018-09-28

Licensed under

댓글