首页 > 代码库 > 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实现简单的单链表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。