phpチェーンテーブルの使用例の分析
3657 ワード
この例では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プログラム設計に役立つことを願っています.