最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2015年07月09日 11:15:40   作者:silencer  
這篇文章主要介紹了php鏈表用法,實(shí)例分析了php創(chuàng)建鏈表及針對(duì)鏈表節(jié)點(diǎn)的增加、刪除、更新與遍歷等常用操作,需要的朋友可以參考下

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

這里簡(jiǎn)單介紹了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;//長(zhǎng)度
  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--要訪問(wèn)的節(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);   
  }
}
?>

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

相關(guān)文章

  • php數(shù)組使用規(guī)則分析

    php數(shù)組使用規(guī)則分析

    這篇文章主要介紹了php數(shù)組使用規(guī)則,實(shí)例分析了php中數(shù)組的用法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-02-02
  • php header 詳細(xì)使用說(shuō)明與使用心得

    php header 詳細(xì)使用說(shuō)明與使用心得

    下面是關(guān)于header函數(shù)的詳細(xì)使用說(shuō)明
    2009-11-11
  • How do I change MySQL timezone?

    How do I change MySQL timezone?

    The MySQL timezone is set to MST (-7 hours GMT/UTC) and is not configurable by you. MySQL is only capable of having 1 timezone setting per mysql daemon. Therefore, you cannot select NOW() and expect a result in a timezone other than MST.
    2008-03-03
  • PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解

    PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解

    這篇文章主要介紹了PHP實(shí)現(xiàn)基本留言板功能,結(jié)合實(shí)例形式分析了PHP實(shí)現(xiàn)基本留言板功能的相關(guān)原理、數(shù)據(jù)庫(kù)構(gòu)建、功能實(shí)現(xiàn)等步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2020-03-03
  • php計(jì)算兩個(gè)文件相對(duì)路徑的方法

    php計(jì)算兩個(gè)文件相對(duì)路徑的方法

    這篇文章主要介紹了php計(jì)算兩個(gè)文件相對(duì)路徑的方法,涉及php操作字符串的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • PHP里8個(gè)鮮為人知的安全函數(shù)分析

    PHP里8個(gè)鮮為人知的安全函數(shù)分析

    這篇文章主要介紹了PHP里8個(gè)鮮為人知的安全函數(shù),較為詳細(xì)的分析了addslashes、htmlentities、htmlspecialchars及md5等函數(shù)在PHP程序設(shè)計(jì)安全中所起到重要作用,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2014-12-12
  • php的$_FILES的臨時(shí)儲(chǔ)存文件與回收機(jī)制實(shí)測(cè)過(guò)程

    php的$_FILES的臨時(shí)儲(chǔ)存文件與回收機(jī)制實(shí)測(cè)過(guò)程

    上傳文件是怎么個(gè)原理,大概的想了下,應(yīng)該是一種回收機(jī)制:點(diǎn)擊了臨時(shí)文件空間,那么,php自身應(yīng)該自己維護(hù)這塊空間的回收,具體的測(cè)試過(guò)程如下,感興趣的朋友可以參考下哈
    2013-07-07
  • 洪恩在線成語(yǔ)詞典小偷程序php版

    洪恩在線成語(yǔ)詞典小偷程序php版

    去年在學(xué)習(xí)用php做小偷程序時(shí)的一個(gè)練習(xí)之作,希望能給有同樣需求的朋友帶來(lái)些幫助,程序主要流程是獲取洪恩在線的成語(yǔ)詞典查詢結(jié)果并在當(dāng)前頁(yè)面顯示出來(lái)(俗稱小偷程序),使用語(yǔ)言為php
    2012-04-04
  • PHP curl 獲取響應(yīng)的狀態(tài)碼的方法

    PHP curl 獲取響應(yīng)的狀態(tài)碼的方法

    PHP curl可以從服務(wù)器端模擬一個(gè)http請(qǐng)求,例如抓取網(wǎng)頁(yè)、模擬登陸等,想要獲取狀態(tài)碼,需要在執(zhí)行curl_exec后再通過(guò)curl_getinfo來(lái)獲取
    2014-01-01
  • wamp服務(wù)器訪問(wèn)php非常緩慢的解決過(guò)程

    wamp服務(wù)器訪問(wèn)php非常緩慢的解決過(guò)程

    這篇文章主要介紹了wamp服務(wù)器訪問(wèn)php非常緩慢的解決過(guò)程,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
    2015-07-07

最新評(píng)論

晋城| 奇台县| 宣汉县| 玉林市| 岗巴县| 商都县| 马关县| 抚顺县| 伊金霍洛旗| 曲阳县| 珲春市| 平原县| 南通市| 西青区| 定结县| 广宁县| 汉源县| 老河口市| 大丰市| 乌拉特中旗| 襄樊市| 比如县| 渝北区| 勃利县| 宝兴县| 蓝山县| 北川| 顺义区| 全南县| 晋宁县| 云和县| 茶陵县| 日喀则市| 麻栗坡县| 沅陵县| 淳化县| 衡水市| 开平市| 舒兰市| 保康县| 巴东县|