久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php實現(xiàn)順序線性表

      php實現(xiàn)順序線性表

      什么是線性順序表?

      線性順序表是指按照順序在內(nèi)存進(jìn)行存儲,除起始和結(jié)尾以外都是一一連接的(一般都是用一維數(shù)組的形式表現(xiàn))。

      (免費學(xué)習(xí)視頻教程分享:php視頻教程)

      實例代碼如下所示:

      <?php /*  * GetElem: 返回線性表中第$index個數(shù)據(jù)元素  * ListLength: 返回線性表的長度  * LocateElem: 返回給定的數(shù)據(jù)元素在線性表中的位置  * PriorElem: 返回指定元素的前一個元素  * NextElem: 返回指定元素的后一個元素  * ListInsert: 在第index的位置插入元素elem  * ListDelete: 刪除第index位置的元素elem  */ class Sequence {   public $seqArr;   public $length;   public function __construct($arr) {     $this->seqArr = $arr;     $this->length = count($arr);   }   /*    * 返回線性表中第$index個數(shù)據(jù)元素    */   public function GetElem($index) {     if (($this->length) == 0 || $index < 0 || ($index > $this->length)) {       return "Error";     }     return $this->seqArr[$index - 1];   }   /*    * 返回線性表的長度    *    */   public function ListLength() {     return $this->length;   }   /*    * 返回給定的數(shù)據(jù)元素在線性表中的位置    */   public function LocateElem($elem) {     for ($i = 0; $i < ($this->length); $i++) {       if (($this->seqArr[$i]) == $elem) {         return $i + 1;       }     }   }   /*    * PriorElem: 返回指定元素的前一個元素    */   public function PriorElem($elem) {     for ($i = 0; $i < ($this->length); $i++) {       if (($this->seqArr[$i]) == $elem) {         if ($i == 0) {           return "Error (is null) ";         } else {           return $this->seqArr[$i - 1];         }       }     }   }   /*    * NextElem: 返回指定元素的后一個元素    */   public function NextElem($elem) {     for ($i = 0; $i < ($this->length); $i++) {       if (($this->seqArr[$i]) == $elem) {         return $this->seqArr[$i + 1];       }     }   }   /*    * ListInsert: 在第index的位置插入元素elem    */   public function ListInsert($index, $elem) {     if (($this->length) == 0 || $index < 0 || $index > ($this->length)) {       return "Error";     }     for ($i = $index; $i < ($this->length); $i++) {       $this->seqArr[$i + 1] = $this->seqArr[$i];     }     $this->seqArr[$index] = $elem;     $this->length = $this->length + 1;     return $this->seqArr;   }   /*    * ListDelete: 刪除第index位置的元素    */   public function ListDelete($index) {     if (($this->length) == 0 || $index < 0 || $index > ($this->length - 1)) {       return "Error";     }     unset($this->seqArr[$index]);     $this->length--;     return $this->seqArr;   } } ?>

      相關(guān)文章教程分享:php教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號