线性表是最基本、最简单、也是最常用的一种数据结构。线性表(linearlist)是数据结构的一种,一个线性表是n个具有相同特性的数据元素的有限序列。线性表:即零个或多个数据元素的有限序列。
线性表的数据结构:即数据元素依此存储在一段地址连续的存储单元内。在高级语言中就表现为数组。
1.php中的数组实际上是有序映射,可以当成数组,列表,散列表,字典,集合,栈,队列,不是固定的长度
2.数组定义中多个单元都使用了同一个键名,则只使用了最后一个,之前的都被覆盖了
3.想要函数的一个参数总是通过引用传递,可以在函数定义中该参数的前面加上符号&
4.php的引用是别名,就是两个不同的变量名字指向相同的内容;“默认情况下对象是通过引用传递的”。但其实这不是完全正确的,当对象作为参数传递,作为结果返回,或者赋值给另外一个变量,另外一个变量跟原来的不是引用的关系,只是他们都保存着同一个标识符的拷贝
参数解析
destroylist:销毁顺序线性表
clearlist:将线性表重置为空
listempty:判断线性表是否为空
listlength:返回线性表的长度
getelem:返回线性表中第$index个数据元素
locateelem:返回给定的数据元素在线性表中的位置
priorelem:返回指定元素的前一个元素
nextelem:返回指定元素的后一个元素
listinsert:在第index的位置插入元素elem
listdelete:删除第index位置的元素elemphp线性表顺序存储结构原理示例
<?php
class seqstorelist {
public $sqarr;
public static $length;
public function __construct($sqarr){
$this->sqarr=$sqarr;
self::$length=count($sqarr);
}
//销毁顺序线性表
public function destroylist(){
$this->sqarr=null;
self::$length=0;
}
//将线性表重置为空
public function clearlist(){
$this->sqarr=array();
self::$length=0;
}
//判断线性表是否为空
public function listempty(){
if(self::$length==0){
return 'is null';
}else{
return 'not null';
}
}
//返回线性表的长度
public function listlength(){
return self::$length;
}
//返回线性表中第$index个数据元素
public function getelem($index){
if(self::$length==0 || $index<1 || $index>self::$length){
return 'error';
}
return $this->sqarr[$index-1];
}
//返回给定的数据元素在线性表中的位置
public function locateelem($elem){
for($i=0;$i<self::$length;$i++){
if($this->sqarr[$i] == $elem){
break;
}
}
if($i>=self::$length){
return 'error';
}
return $i+1;
}
//返回指定元素的前一个元素
public function priorelem($cur_elem){
for($i=0;$i<self::$length;$i++){
if($this->sqarr[$i] == $cur_elem){
break;
}
}
if($i==0 || $i>=self::$length){
return 'error';
}
return $this->sqarr[$i-1];
}
//返回指定元素的后一个元素
public function nextelem($cur_elem){
for($i=0;$i<self::$length;$i++){
if($this->sqarr[$i] == $cur_elem){
break;
}
}
if($i>=self::$length-1){
return 'error';
}
return $this->sqarr[$i+1];
}
//在第index的位置插入元素elem
public function listinsert($index,$elem){
if($index<1 || $index>self::$length+1){
return 'error';
}
if($index<=self::$length){
for($i=self::$length-1;$i>=$index-1;$i--){
$this->sqarr[$i+1]=$this->sqarr[$i];
}
}
$this->sqarr[$index-1]=$elem;
self::$length++;
return 'ok';
}
//listdelete: 删除第index位置的元素elem
public function listdelete($index){
if($index<1 || $index>self::$length+1){
return 'error';
}
if($index<self::$length){
for($i=$index;$i<self::$length;$i++){
$this->sqarr[$i-1]=$this->sqarr[$i];
}
}
self::$length--;
return $this->sqarr[$index-1];
}
}
如何成为代理-市场咨询非法信息监测里面并没有任何提示啊你的成本才多少 要不要那么贵?做网站哪个好阿里云服务器续费为什么贵买了服务器之后一定要买云盾吗biz是什么域名?biz域名有什么特殊的意义吗?阿里云服务器怎么修改服务器地址