class list {
private $size = 100;
private $arr = [];
public function __construct(int $size)
{
if ($size > 1) {
$this->size = $size;
}
}
//入
public function push(string $data)
{
if (count($this->arr) == $this->size) {
return false;
} else {
$this->arr[] = $data;
return true;
}
}
//出
public function pull()
{
if (empty($this->arr)) {
return false;
} else {
return array_shift($this->arr);
}
}
//是否为空
public function isEmpty()
{
return empty($this->arr);
}
//长度
public function getSize()
{
return count($this->arr);
}
}
PHP实现一个类,实现一个数组的循环队列,入队列、出队列
猜你喜欢
转载自blog.csdn.net/Alen_xiaoxin/article/details/105235196
今日推荐
周排行