php鏈表用法執行個體分析,php用法執行個體分析_PHP教程

來源:互聯網
上載者:User

php鏈表用法執行個體分析,php用法執行個體分析


本文執行個體講述了php鏈表用法。分享給大家供大家參考。具體如下:

這裡簡單介紹了php鏈表的基本用法,包括鏈表節點的建立、遍曆、更新等操作。

<?php/** * @author MzXy * @copyright 2011 * @param PHP鏈表 *//****節點類*/class Node{  private $Data;//節點資料  private $Next;//下一節點  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;//前端節點  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鏈表的基本用...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.