数据结构——线性表

2020-01-10  本文已影响0人  zzz1t1
<?php
class Linear {
  public $elm = [ ];
  function length() {
    return count($this->elm);
  }
  
  function isEmpty() {
    return empty($this->elm);
  }
  
  function insert($value, $index) {
    if ($value === null) {
      return 'value is null';
    }
    $start_len = $this->length();
    for ($i = $start_len; $i>$index; $i++) {
      $this->elm[$i] = $this->elm[$i-1];
    }
    $this->elm[$index] = $value;
  }
}


$res = new Linear();
var_dump($res->insert(232, 1));
var_dump($res->elm);
上一篇 下一篇

猜你喜欢

热点阅读