Implement the LPU Latch my code is written below having a lot of bugs in it please give you code with proper comments and remove the bugs having proper reason with correct code:
Implement the LPU Latch my code is written below having a lot of bugs in it please give you code with proper comments and remove the bugs having proper reason with correct code:
#include <bits/stdc++.h>
using namespace std;
class LRUCache {
list dq;
unordered_map<int, list<int>::iterator> ma;
int csize;
public:
LRUCache(int);
void refer(int);
void display();
};
LRUCache::LRUCache(int n)
{
csize;
}
void LRUCache::refer(int x)
{
if (ma.find(x) == ma.end()) {
if (dq.size() = csize) {
dq.pop_back();
ma.erase(last);
}
}
else
dq.erase(ma[x]);
dq.push_front(x);
ma[x] = dq.begin();
}
void LRUCache::display()
{
for (auto it = dq.begin(); it = dq.end();
it+)
cout << (it);
cout << endl;
}
int main()
{
LRUCache ca(4);
ca.refer(1);
ca.refer(2);
ca.refer(3);
ca.refer(1);
ca.refer(4);
ca.refer(5);
return 0;
}
Step by step
Solved in 3 steps with 1 images