(int key)
| 30 | } |
| 31 | |
| 32 | public int get(int key) { |
| 33 | if (!cache.containsKey(key)) { |
| 34 | return -1; |
| 35 | } |
| 36 | else { |
| 37 | // To make this key the most recently used, remove its node and |
| 38 | // re-add it to the tail of the linked list. |
| 39 | remove(cache.get(key)); |
| 40 | addToTail(cache.get(key)); |
| 41 | return cache.get(key).val; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | public void put(int key, int val) { |
| 46 | // If a node with this key already exists, remove it from the |