Destructor: Cleans up dynamically allocated resources to prevent memory leaks. Implemented if time permits during an interview.
| 29 | // to prevent memory leaks. Implemented if time permits |
| 30 | // during an interview. |
| 31 | ~LRUCache() { |
| 32 | // Delete all nodes in the linked list. |
| 33 | DoublyLinkedListNode* current = head; |
| 34 | while (current != nullptr) { |
| 35 | DoublyLinkedListNode* nextNode = current->next; |
| 36 | delete current; |
| 37 | current = nextNode; |
| 38 | } |
| 39 | // Clear the hashmap. |
| 40 | hashmap.clear(); |
| 41 | } |
| 42 | |
| 43 | int get(int key) { |
| 44 | if (hashmap.find(key) == hashmap.end()) { |
nothing calls this directly
no outgoing calls
no test coverage detected