php 顺序线性表
程序员文章站
2022-04-27 12:58:24
...
seqArr = $arr; $this->length = count($arr); } /* * 返回线性表中第$index个数据元素 */ public function GetElem($index) { if (($this->length) == 0 || $index $this->length)) { return "Error"; } return $this->seqArr[$index - 1]; } /* * 返回线性表的长度 * */ public function ListLength() { return $this->length; } /* * 返回给定的数据元素在线性表中的位置 */ public function LocateElem($elem) { for ($i = 0; $i length); $i++) { if (($this->seqArr[$i]) == $elem) { return $i + 1; } } } /* * PriorElem: 返回指定元素的前一个元素 */ public function PriorElem($elem) { for ($i = 0; $i 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 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 ($this->length)) { return "Error"; } for ($i = $index; $i 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 ($this->length - 1)) { return "Error"; } unset($this->seqArr[$index]); array_values($this->seqArr); return $this->seqArr; }}?>
推荐阅读
-
php前景分析(行业发展现状及前景分析)
-
使用PHP+Redis实现延迟任务,实现自动取消订单功能
-
nginx比apache处理静态文件速度快,但是nginx处理大量并发的php请求时,容易出现502错误,频率大概是多少
-
ascii码值大小顺序(常见ascii码值)
-
配置php环境(php开发环境的配置过程)
-
CentOS7系统搭建LAMP及更新PHP版本操作详解
-
百度网盟代码优化 推广单元请求顺序优化技巧
-
EpiiAdmin 开源的php交互性管理后台框架, 让复杂的交互变得更简单!Phper快速搭建交互性平台的开发框架,基于Thinkphp5.1+Adminlte3.0+Require.js。
-
php源码怎么搭建网站教程(详解php服务器环境搭建及配置)
-
php数组转字符串函数有哪些(最实用的2种方法)