国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 昌宁县| 和平县| 柳州市| 德庆县| 凤山市| 浙江省| 中卫市| 东乡县| 博湖县| 嘉义市| 华安县| 思茅市| 保靖县| 金沙县| 玉树县| 白朗县| 隆安县| 崇阳县| 唐河县| 天门市| 磐安县| 龙胜| 德清县| 岳西县| 莲花县| 罗甸县| 河曲县| 衡阳市| 富川| 晋宁县| 亚东县| 安顺市| 山东省| 青州市| 景东| 柘城县| 丰都县| 拜泉县| 荣昌县| 石阡县| 南阳市|