src/Datastructure/Lists/LinkedLists/DoublyLinkedList.php
public function prepend(?Node $node): bool {
        if ($node === null) {
            return false;
        }
        /*
         * need to clone the object otherwise the object
         * references are going crazy.
         *
         * Furthermore, setting previous and next to null
         * as they will be set later.
         */
        $newNode = clone $node;
        $newNode->setPrevious(null);
        $newNode->setNext(null);

        if ($this->getHead() === null) {
            $this->setHead($newNode);
            return true;
        }
        $head = $this->getHead();
        $head->setPrevious($newNode);
        $newNode->setNext($head);
        $this->setHead($newNode);
        return true;
    }
public function prepend(?Node $node): bool {
        if ($node === null) {
            return false;
        }
        /*
         * need to clone the object otherwise the object
         * references are going crazy.
         *
         * Furthermore, setting previous and next to null
         * as they will be set later.
         */
        $newNode = clone $node;
        $newNode->setPrevious(null);
        $newNode->setNext(null);

        if ($this->getHead() === null) {
            $this->setHead($newNode);
            return true;
        }
        $head = $this->getHead();
        $head->setPrevious($newNode);
        $newNode->setNext($head);
        $this->setHead($newNode);
        return true;
    }
public function prepend ( ? Node $ node ) : bool { if ( $ node === null ) { return false ; } /*
         * need to clone the object otherwise the object
         * references are going crazy.
         *
         * Furthermore, setting previous and next to null
         * as they will be set later.
         */ $ newNode = clone $ node ; $ newNode -> setPrevious ( null ) ; $ newNode -> setNext ( null ) ; if ( $ this -> getHead ( ) === null ) { $ this -> setHead ( $ newNode ) ; return true ; } $ head = $ this -> getHead ( ) ; $ head -> setPrevious ( $ newNode ) ; $ newNode -> setNext ( $ head ) ; $ this -> setHead ( $ newNode ) ; return true ; }
prepends a node on top of the list

@param \doganoo\PHPAlgorithms\Datastructure\Lists\Node|null $node
@return bool
prepends a node on top of the list