LRU是Least Recently Used 近期最少使用算法,一种页面置换算法,其实现较为简单,Java实现代码如下
1 import java.util.LinkedList; 2 import java.util.List; 3 4 public class LRU { 5 6 private List<Integer> executeSeries = new LinkedList<Integer>(); 7 8 public LRU(Integer[] executeSeries) { 9 for (Integer temp : executeSeries) { 10 put(temp); 11 } 12 } 13 14 public void put(Integer cur) { 15 if (cur == null) { 16 return; 17 } 18 for (Integer temp : executeSeries) { 19 if (cur.equals(temp)) { 20 executeSeries.remove(temp); 21 break; 22 } 23 } 24 executeSeries.add(cur); 25 System.out.println(ShowUtil.toString(executeSeries)); 26 } 27 28 public static void main(String[] args) { 29 // TODO Auto-generated method stub 30 Integer[] executeSeries = {1,2,3,1,2,3,3,4}; 31 new LRU(executeSeries); 32 } 33 }
LRU近期最少使用算法
时间: 2024-10-17 13:39:29