src/Common/Abstracts/AbstractLinkedList.php
public function getMiddleNode(): ?IUnaryNode {
        $head = $this->getHead();

        if (null === $head) return null;

        $p = $head;
        $q = $head;

        while (null !== $p &&
            null !== $q && //actually not really necessary since $p and $q point to the same object
            null !== $q->getNext()
        ) {
            $p = $p->getNext();
            $q = $q->getNext()->getNext();
        }
        return $p;
    }
public function getMiddleNode(): ?IUnaryNode {
        $head = $this->getHead();

        if (null === $head) return null;

        $p = $head;
        $q = $head;

        while (null !== $p &&
            null !== $q && //actually not really necessary since $p and $q point to the same object
            null !== $q->getNext()
        ) {
            $p = $p->getNext();
            $q = $q->getNext()->getNext();
        }
        return $p;
    }
public function getMiddleNode ( ) : ? IUnaryNode { $ head = $ this -> getHead ( ) ; if ( null === $ head ) return null ; $ p = $ head ; $ q = $ head ; while ( null !== $ p && null !== $ q && //actually not really necessary since $p and $q point to the same object null !== $ q -> getNext ( ) ) { $ p = $ p -> getNext ( ) ; $ q = $ q -> getNext ( ) -> getNext ( ) ; } return $ p ; }
returns the middle node of the linked list

@return IUnaryNode|null
returns the middle node of the linked list