public
function
addLink(
$node
) {
$current
=
$this
->header;
while
(
$current
->next != null ) {
if
(
$current
->next->id >
$node
->id) {
break
;
}
$current
=
$current
->next;
}
$node
->next =
$current
->next;
$current
->next =
$node
;
}
//
删除链表节点
public
function
delLink(
$id
) {
$current
=
$this
->header;
$flag
= false;
while
(
$current
->next != null ) {
if
(
$current
->next->id ==
$id
) {
$flag
= true;
break
;
}
$current
=
$current
->next;
}
if
(
$flag
) {
$current
->next =
$current
->next->next;
}
else
{
echo
"未找到 id=" .
$id
. "的节点!<br>";
}
}
//
获取链表
public
function
getLinkList() {
$current
=
$this
->header;
if
(
$current
->next == null) {
echo
("链表为空!");
return
;
}
while
(
$current
->next != null ) {
echo
'id:' .
$current
->next->id . ' name:' .
$current
->next->name . "<br>";
if
(
$current
->next->next == null) {
break
;