本文操作环境:windows7系统、PHP7.1版、DELL G3电脑php双向队列什么意思?PHP — 用PHP实现一个双向队列简介deque,全名double-ended queue,是一种具有队列和栈的性质的数据结构。双端队列中的元素
本文操作环境:windows7系统、PHP7.1版、DELL G3电脑
php双向队列什么意思?
PHP — 用PHP实现一个双向队列
简介
deque,全名double-ended queue,是一种具有队列和栈的性质的数据结构。双端队列中的元素可以从两端弹出,其限定插入和删除操作在表的两端进行。双向队列(双端队列)就像是一个队列,但是你可以在任何一端添加或移除元素。
参考:Http://zh.wikipedia.org/zh-cn/%E5%8F%8C%E7%AB%AF%E9%98%9F%E5%88%97
php实现代码
<?php
class DoubleQueue
{
public $queue = array();
public function addLast($value)
{
return array_push($this->queue,$value);
}
public function removeLast()
{
return array_pop($this->queue);
}
public function addFirst($value)
{
return array_unshift($this->queue,$value);
}
public function removeFirst()
{
return array_shift($this->queue);
}
public function makeEmpty()
{
unset($this->queue);
}
public function getFirst()
{
return reset($this->queue);
}
public function getLast()
{
return end($this->queue);
}
public function getLength()
{
return count($this->queue);
}
}
--结束END--
本文标题: php双向队列什么意思
本文链接: https://www.lsjlt.com/news/441.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0