$current = $this->header; $q = $current->next; $current->next = null; while ($q != null) { $temp = $q; $q = $q->next; $temp->next = $current->next; $current->next = $temp; } } public function getHeader() { return $this->header; } } $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')); var_dump($lists->getHeader()); // $lists->getLinkList (); // echo "<br>-----------翻转节点--------------<br>"; // $lists->reverseList (); // $lists->getLinkList (); // echo "<br>-----------删除节点--------------<br>"; // $lists->delLink ( 5 ); // $lists->getLinkList (); // echo "<br>-----------更新节点名称--------------<br>";
{ $current = $this->header; 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);