First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack. George Carrette

LRU cache

Language Java | Level Intermediate | Category Algorithms | August 4, 2015 8:42 am


Algorithm Problem Description

LRU cache algorithm discards the least recently used items first. This algorithm requires keeping track of what was used when, which is expensive if one wants to make sure the algorithm always discards the least recently used item.

Write a program to implement LRU Cache.

Output

          	        
          	        

LRU Cache unitized with size 5
Display LRU:
[10]= [20]
[9]= [18]
[8]= [16]
[7]= [14]
[6]= [12]

LRU Cache after retrieving 7
[7]= [14]
[10]= [20]
[9]= [18]
[8]= [16]
[6]= [12]

LRU cache on adding one more item. It will replace last one
[11]= [22]
[7]= [14]
[10]= [20]
[9]= [18]
[8]= [16]

          	        
          	        				    


Comments



Please login to add comments.