Untitled
unknown
plain_text
3 years ago
1.1 kB
2
Indexable
public class Main { public static void main (String[] args) { LRUCache<Integer, Integer> cache = new LRUCache1<>(3); cache.put(1, 1); cache.put(2, 2); cache.put(3, 3); System.out.println("1 " + cache.get(1)); System.out.println("2 " + cache.get(2)); System.out.println("3 " + cache.get(3)); System.out.println("0 " + cache.get(0)); System.out.println("0 " + cache.get(0)); System.out.println("0 " + cache.get(0)); // should print // 1 1 // 2 2 // 3 3 // 0 null // 0 null // 0 null cache.get(1); cache.get(2); cache.put(2, 5); cache.put(4, 4); System.out.println("--------------"); System.out.println("1 " + cache.get(1)); System.out.println("2 " + cache.get(2)); System.out.println("3 " + cache.get(3)); System.out.println("4 " + cache.get(4)); // should print // 1 1 // 2 5 // 3 null // 4 4 } }
Editor is loading...