background image

$current

 = 

$current

->next; 



 

//

 

获取节点名字

public

 

function

 getLinkNameById(

$id

) { 

$current

 = 

$this

->header; 

if

 (

$current

->next == null) { 

echo

 "链表为空!"; 

return

while

 ( 

$current

->next != null ) { 

if

 (

$current

->id == 

$id

) { 

break

$current

 = 

$current

->next; 

return

 

$current

->name; 


 

//

 

更新节点名称

public

 

function

 updateLink(

$id

$name

) { 

$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' ) );