/** * Remove node * * @param NodeInterface $node */ private function removeNode(NodeInterface $node) { if ($this->length === 0) { return; } if (!$node->getLeft() && !$node->getRight()) { $this->current = $this->first = $this->last = null; } else { if (!$node->getLeft()) { $this->first = $node->getRight(); $this->first->unsetLeft(); $this->current = $node->getRight(); } else { if (!$node->getRight()) { $this->last = $node->getLeft(); $this->last->unsetRight(); $this->current = null; } else { $node->getLeft()->setRight($node->getRight()); $node->getRight()->setLeft($node->getLeft()); $this->current = $node->getRight(); } } } $node = null; $this->length--; }