您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php链表用法实例分析,php用法实例分析_PHP教程

2025/11/21 20:45:24发布15次查看
php链表用法实例分析,php用法实例分析本文实例讲述了php链表用法。分享给大家供大家参考。具体如下:
这里简单介绍了php链表的基本用法,包括链表节点的创建、遍历、更新等操作。
data=$value; } public function setnext($value){ $this->next=$value; } public function getdata(){ return $this->data; } public function getnext(){ return $this->next; } public function __construct($data,$next){ $this->setdata($data); $this->setnext($next); }}//功能类class linklist{ private $header;//头节点 private $size;//长度 public function getsize(){ $i=0; $node=$this->header; while($node->getnext()!=null) { $i++; $node=$node->getnext(); } return $i; } public function setheader($value){ $this->header=$value; } public function getheader(){ return $this->header; } public function __construct(){ header(content-type:text/html; charset=utf-8); $this->setheader(new node(null,null)); } /** *@author mzxy *@param $data--要添加节点的数据 * */ public function add($data) { $node=$this->header; while($node->getnext()!=null) { $node=$node->getnext(); } $node->setnext(new node($data,null)); } /** *@author mzxy *@param $data--要移除节点的数据 * */ public function removeat($data) { $node=$this->header; while($node->getdata()!=$data) { $node=$node->getnext(); } $node->setnext($node->getnext()); $node->setdata($node->getnext()->getdata()); } /** *@author mzxy *@param 遍历 * */ public function get() { $node=$this->header; if($node->getnext()==null){ print(数据集为空!); return; } while($node->getnext()!=null) { print($node->getnext()->getdata()); if($node->getnext()->getnext()==null){break;} $node=$node->getnext(); } } /** *@author mzxy *@param $data--要访问的节点的数据 * @param 此方法只是演示不具有实际意义 * */ public function getat($data) { $node=$this->header->getnext(); if($node->getnext()==null){ print(数据集为空!); return; } while($node->getdata()!=$data) { if($node->getnext()==null){break;} $node=$node->getnext(); } return $node->getdata(); } /** *@author mzxy *@param $value--需要更新的节点的原数据 --$initial---更新后的数据 * */ public function update($initial,$value) { $node=$this->header->getnext(); if($node->getnext()==null){ print(数据集为空!); return; } while($node->getdata()!=$data) { if($node->getnext()==null){break;} $node=$node->getnext(); } $node->setdata($initial); }}?>
希望本文所述对大家的php程序设计有所帮助。
http://www.bkjia.com/phpjc/1029598.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1029598.htmltecharticlephp链表用法实例分析,php用法实例分析 本文实例讲述了php链表用法。分享给大家供大家参考。具体如下: 这里简单介绍了php链表的基本用...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product