Least recently used caching scheme is a sort of algorithm in which the memory (cache) is given and the no. of pages a cache can hold is also given.
1)Under the class LRUcache another class node is defined having key,val as variables and prev and next as node type pointers
and a constructor is defined.
2)The key and value of head and tail are initialised as -1,-1.
3)Unordered map is used which will store the key value pair and a constructor or class lrucache is defined in which the value of head's next is assigned as tail and tail's previous id assigned as head.
4) addnode and deletenode are two functions that will add a node and delete respectively.
5)Get() is used to get a value at a particular position(key).
6)Put() is used to put a value at particular position(key).
7)Finally in main() fumction, put() and get() function are called.
Submitted by Muskan Chaturvedi (Muskan01)
Download packets of source code on Coders Packet
Comments