国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

php鏈表用法實(shí)例分析

2024-04-25 20:38:43
字體:
供稿:網(wǎng)友

本文實(shí)例講述了php鏈表用法。分享給大家供大家參考。具體如下:

這里簡單介紹了php鏈表的基本用法,包括鏈表節(jié)點(diǎn)的創(chuàng)建、遍歷、更新等操作。

<?php

/**

* @author MzXy

* @copyright 2011

* @param PHP鏈表

*/

/**

*

*節(jié)點(diǎn)類

*/

class Node

{

private $Data;//節(jié)點(diǎn)數(shù)據(jù)

private $Next;//下一節(jié)點(diǎn)

public function setData($value){

$this->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;//頭節(jié)點(diǎn)

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--要添加節(jié)點(diǎn)的數(shù)據(jù)

*

*/

public function add($data)

{

$node=$this->header;

while($node->getNext()!=null)

{

$node=$node->getNext();

}

$node->setNext(new Node($data,null));

}

/**

*@author MzXy

*@param $data--要移除節(jié)點(diǎn)的數(shù)據(jù)

*

*/

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("數(shù)據(jù)集為空!");

return;

}

while($node->getNext()!=null)

{

print($node->getNext()->getData());

if($node->getNext()->getNext()==null){break;}

$node=$node->getNext();

}

}

/**

*@author MzXy

*@param $data--要訪問的節(jié)點(diǎn)的數(shù)據(jù)

* @param 此方法只是演示不具有實(shí)際意義

*

*/

public function getAt($data)

{

$node=$this->header->getNext();

if($node->getNext()==null){

print("數(shù)據(jù)集為空!");

return;

}

while($node->getData()!=$data)

{

if($node->getNext()==null){break;}

$node=$node->getNext();

}

return $node->getData();

}

/**

*@author MzXy

*@param $value--需要更新的節(jié)點(diǎn)的原數(shù)據(jù) --$initial---更新后的數(shù)據(jù)

*

*/

public function update($initial,$value)

{

$node=$this->header->getNext();

if($node->getNext()==null){

print("數(shù)據(jù)集為空!");

return;

}

while($node->getData()!=$data)

{

if($node->getNext()==null){break;}

$node=$node->getNext();

}

$node->setData($initial);

}

}

?>

希望本文所述對大家的php程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乐陵市| 苍南县| 将乐县| 咸阳市| 华蓥市| 吴桥县| 武宣县| 堆龙德庆县| 大同市| 彭水| 嘉义市| 门头沟区| 玉田县| 普格县| 芜湖县| 汾西县| 崇礼县| 巴中市| 武城县| 澜沧| 闵行区| 石渠县| 彭山县| 南充市| 临武县| 红河县| 名山县| 洞头县| 宁陕县| 吐鲁番市| 巴林右旗| 麻江县| 苏尼特右旗| 库车县| 花垣县| 印江| 大足县| 水富县| 天柱县| 揭东县| 大邑县|