src/Common/Abstracts/AbstractLinkedList.php
public function removeDuplicates() {
        $tortoise = $this->head;

        while ($tortoise !== null) {
            $hare = $tortoise;
            while ($hare->getNext() !== null) {
                if (Comparator::equals($hare->getNext()->getValue(), $tortoise->getValue())) {
                    $hare->setNext($hare->getNext()->getNext());
                } else {
                    $hare = $hare->getNext();
                }
            }
            $tortoise = $tortoise->getNext();
        }
    }
public function removeDuplicates() {
        $tortoise = $this->head;

        while ($tortoise !== null) {
            $hare = $tortoise;
            while ($hare->getNext() !== null) {
                if (Comparator::equals($hare->getNext()->getValue(), $tortoise->getValue())) {
                    $hare->setNext($hare->getNext()->getNext());
                } else {
                    $hare = $hare->getNext();
                }
            }
            $tortoise = $tortoise->getNext();
        }
    }
public function removeDuplicates ( ) { $ tortoise = $ this -> head ; while ( $ tortoise !== null ) { $ hare = $ tortoise ; while ( $ hare -> getNext ( ) !== null ) { if ( Comparator :: equals ( $ hare -> getNext ( ) -> getValue ( ) , $ tortoise -> getValue ( ) ) ) { $ hare -> setNext ( $ hare -> getNext ( ) -> getNext ( ) ) ; } else { $ hare = $ hare -> getNext ( ) ; } } $ tortoise = $ tortoise -> getNext ( ) ; } }
The method uses the runner technique in order to iterate over
head twice. If the list contains duplicates, the next-next is set
as the next node of the current node.
The method uses the runner technique in order to iterate over head twice . If the list contains duplicates the next - next is set as the next node of the current node .