PHP 单链表

<?php 
 class Hero {
 public $no;
 public $name;
 public $nickname;
 public $next=null;
 
 public function __construct($no="",$name="",$nickname=""){
 
  $this->no = $no;
  $this->name = $name;
  $this->nickname = $nickname;
 
 }
 }
 
 $head = new Hero();
 
 $hero1 = new Hero(1,‘宋江‘,‘及时雨‘);
 $head->next = $hero1;
 $hero2 = new Hero(2,‘卢俊义‘,‘玉麒麟‘);
 $hero1->next = $hero2;

 
 function addhero($head,$hero){
 
 }
 
	 function showhero($head){
	 $cur = $head;
	 
	 while($cur->next!=null){
	 echo ‘<br/>编号‘.$cur->next->no.‘name‘.$cur->next->name.‘nickname‘.$cur->next->nickname;
	 $cur = $cur->next;
	 }

 }
 showhero($head);

?>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。