- <?php
- class DoubleQueue
- {
- public $queue = array();
- /**(尾部)入队 **/
- public function push($value)
- {
- return array_push($this->queue,$value);
- }
- /**(尾部)出队**/
- public function pop()
- {
- return array_pop($this->queue);
- }
- /**(头部)入队**/
- public function enq($value)
- {
- return array_unshift($this->queue,$value);
- }
- /**(头部)出队**/
- public function deq()
- {
- return array_shift($this->queue);
- }
- /**清空队列**/
- public function makeEmpty()
- {
- return unset($this->queue);
- }
- }
- class DoubleDueue
- {
- public $queue = array();
- public function push($value)
- {
- return $this->queue[] = $value;
- }
- public function pop()
- {
- $count = $this->count();
- if($count >= 1)
- {
- $value = $this->queue[$count-1];
- unset($this->queue[$count-1]);
- return $value;
- }
- else
- {
- return false;
- }
- }
- public function enq($value)
- {
- /*不好做*/
- }
- public function deq()
- {
- /*不好做*/
- }
- public function count()
- {
- return count($this->queue);
- }
- public function makeEmpty()
- {
- return unset($this->queue);
- }
- }
- ?>
貌似用这四个函数就行
- array_push — 将一个或多个单元压入数组的末尾(入栈)
- array_unshift — 在数组开头插入一个或多个单元
- array_pop — 将数组最后一个单元弹出(出栈)
- array_shift — 将数组开头的单元移出数组