PHP实现线性表的顺序存储结构
程序员文章站
2022-03-31 20:06:47
...
classSqList
{public$elem;
public$length;
public$size;
}
classLinear
{const LIST_INIT_SIZE = 10;
const LIST_INCREMENT = 5;
private$list = null;
/**
* 构造一个空的线性表
*/publicfunctioninitList()
{$this->list = new SqList();
$this->list->elem = array();
$this->list->length = 0;
$this->list->size = self::LIST_INIT_SIZE;
returntrue;
}
/**
* 销毁线性表
*/publicfunctiondestoryList()
{if (is_object($this->list)) {
$this->list = null;
}
}
/**
* 是否为空表
*/publicfunctionlistEmpty()
{if (is_object($this->list)) {
return$this->list->length == 0 ? true : false;
}
}
/**
* 返回元素个数
*/publicfunctionlistLength()
{if (is_object($this->list)) {
return$this->list->length;
}
}
/**
* 获取指定位置的元素
*/publicfunctiongetElem($i)
{if ($i 1