Example #1
0
        if ($current->next == null) {
            echo "链表为空!";
            return;
        }
        while ($current->next != null) {
            if ($current->id == $id) {
                break;
            }
            $current = $current->next;
        }
        return $current->name = $name;
    }
}
$lists = new singelLinkList();
$lists->addLink(new node(5, 'eeeeee'));
$lists->addLink(new node(1, 'aaaaaa'));
$lists->addLink(new node(6, 'ffffff'));
$lists->addLink(new node(4, 'dddddd'));
$lists->addLink(new node(3, 'cccccc'));
$lists->addLink(new node(2, 'bbbbbb'));
$lists->getLinkList();
echo "<br>-----------删除节点--------------<br>";
$lists->delLink(5);
$lists->getLinkList();
echo "<br>-----------更新节点名称--------------<br>";
$lists->updateLink(3, "222222");
$lists->getLinkList();
echo "<br>-----------获取节点名称--------------<br>";
echo $lists->getLinkNameById(5);
echo "<br>-----------获取链表长度--------------<br>";
echo $lists->getLinkLength();