public function remove($key): bool {
        /** @var \doganoo\PHPAlgorithms\Datastructure\Lists\Node $previous */
        $previous = $head = $this->getHead();
        if ($head === null) {
            return true;
        }
        $i = 1;
        $headSize = $head->size();

        /*
         * The while loop iterates over all nodes until the
         * value is found.
         */
        while ($head !== null && $head->getKey() !== $key) {
            /*
             * since a node is going to be removed from the
             * node chain, the previous element has to be
             * on hold.
             * After previous is set to the actual element,
             * the current element pointer can moved to the
             * next one.
             *
             * If the value is found, $previous points to
             * the previous element of the value that is
             * searched and current points to the next element
             * after that one who should be deleted.
             */
            $previous = $head;
            $head = $head->getNext();
            $i++;
        }

        /*
         * If the value that should be deleted is not in the list,
         * this set instruction assigns the next node to the actual.
         *
         * If the while loop has ended early, the next node is
         * assigned to the previous node of the node that
         * should be deleted (if there is a node present).
         */
        if ($head !== null) {
            $previous->setNext($head->getNext());
        }
        return $i !== $headSize;
    }