algo/csharp/06-linkedlist/LRU缓存实现思路.txt

9 lines
418 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

实现LRU缓存淘汰算法思路
维护一个有序单链表,越靠近链尾的数据是最早访问的。
当有一个新的数据被访问时,
1. 如果数据在缓存中,则将其从原位置删除,然后插入到表头;
2. 如果数据不在缓存中,有两种情况:
1) 链表未满,则将数据插入到表头;
2) 链表已满,则删除尾结点,将新数据插入到表头。