首页 > 代码库 > php实现简单的单链表

php实现简单的单链表

<?php //节点类,数据和指向下一节点指针class Node{	public $data;	public $next;		public function __construct($data,$next=null){		$this->data = http://www.mamicode.com/$data;"<br/>";    		$current = $current->next;    	}    	echo $current->data;    }        }//头结点为空的链表class LinkListOne{	public $header;		public function __construct(){		$this->header = new Node(null);	}		public function add(Node $node){		$current = $this->header;		while($current->next!==null){			$current = $current->next;		}		$current->next = $node;	}		public function show(){		$current = $this->header;		while($current->next!==null){			echo $current->next->data;			echo "<br/>";			$current = $current->next;		}	}}class Client{	public static function main(){		$node1 = new Node(1);		$node2 = new Node(2);		$node3 = new Node(3);		$node4 = new Node(4);		$linklist = new LinkListOne();		$linklist->add($node1);		$linklist->add($node3);		$linklist->add($node4);		$linklist->show();	}}Client::main();?>

  

php实现简单的单链表