-
Notifications
You must be signed in to change notification settings - Fork 0
/
LRUExample.java
70 lines (50 loc) · 1.2 KB
/
LRUExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.Iterator;
public class LRUExample {
public static void main(String[] args) {
LRU<Integer, Integer> lru = new LRU<>(3);
print(lru);
lru.put(1, 1);
print(lru);
lru.put(2, 2);
print(lru);
lru.put(2, 22);
print(lru);
lru.put(3, 3);
print(lru);
lru.put(1, 11);
print(lru);
lru.put(4, 4);
print(lru);
lru.put(4, 44);
print(lru);
lru.put(5, 5);
print(lru);
lru.put(5, 55);
print(lru);
lru.put(4, 444);
print(lru);
lru.remove(1);
print(lru);
lru.remove(2);
print(lru);
lru.remove(3);
print(lru);
lru.remove(4);
print(lru);
lru.put(1, 1);
print(lru);
lru.put(1, 11);
print(lru);
lru.put(2, 2);
print(lru);
lru.put(2, 22);
print(lru);
}
private static void print(LRU<Integer, Integer> lru) {
Iterator<Integer> iterator = lru.valueIterator();
while (iterator.hasNext()) {
System.out.print(iterator.next() + " ");
}
System.out.println();
}
}