Ejemplo n.º 1
0
    }
    //empty linklist
    public function emptyList()
    {
        $this->firstNode == NULL;
    }
    //insertion at index
    public function insert($NewItem, $key)
    {
        if ($key == 0) {
            $this->insertFirst($NewItem);
        } else {
            $link = new ListNode($NewItem);
            $current = $this->firstNode;
            $previous = $this->firstNode;
            for ($i = 0; $i < $key; $i++) {
                $previous = $current;
                $current = $current->next;
            }
            $previous->next = $link;
            $link->next = $current;
            $this->count++;
        }
    }
}
$obj = new LinkList();
$obj->insertFirst($value);
$obj->insert($value, $key);
// at any index
$obj->deleteNode($value);
$obj->readList();