private void addAtTop(LinkedNode nodeToAdd) { nodeToAdd.right = first; nodeToAdd.left = null; if (first != null) { first.left = nodeToAdd; } first = nodeToAdd; if (last == null) { last = first; } }
private void removeNode(LinkedNode nodeToRemove) { if (nodeToRemove.left != null) { nodeToRemove.left.right = nodeToRemove.right; } else { first = nodeToRemove.right; } if (nodeToRemove.right != null) { nodeToRemove.right.left = nodeToRemove.left; } else { last = nodeToRemove.left; } }