void movetofront(CacheNode node) { if (node == head) { return; } if (node == tail) { tail = tail.prev;// tail is moving once step behind } if (node.next != null) { node.next.prev = node.prev; } node.prev.next = node.next; node.prev = null; node.next = head; head.prev = node; head = node; }
void movetoend(CacheNode node) { if (node == head) { return; } if (node == tail) { tail = tail.prev; } if (node.next != null) { node.next.prev = node.prev; } node.prev.next = node.next; node.prev = null; node.next = head; head.prev = node; head = node; }