Ejemplo n.º 1
0
        if ($node == NULL) {
            //if $node points to NULL
            echo "Linked List is empty";
            return NULL;
        }
        while ($node->next != NULL) {
            echo "Node value is " . $node->value . "<br />";
            $node = $node->next;
            //now have $node point to where $node->next is pointing to
        }
        echo "Node value is " . $node->value . "<br />";
        //have it print the last node value
    }
}
$dll = new DoublyLinkedList();
//creates a new instance of the doubly linked list
$dll->add(5);
//should add a new node with the value of 5
$dll->add(7);
//should add a new node with the value of 7
$dll->add(10);
$dll->removeAllNodesWithValueOf(7);
//should remove all nodes with value of 7
$dll->remove(1);
//removes node of position 1
$dll->add(3);
//should add a new node with the value of 3
$dll->insert(1, 100);
//insert a new node of value 100 in the position 1
$dll->printValues();
//should print all the values in the doubly linked list