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

?>

 

posted on 2015-03-26 21:14  手撕高达的村长  阅读(129)  评论(0编辑  收藏  举报

导航