PHP two-way queue code

不言
Release: 2023-04-02 11:56:01
Original
1329 people have browsed it

This article mainly introduces the PHP two-way queue, which has certain reference value. Now I share it with you. Friends in need can refer to it.

<?php
    class Deque{
        public $queue = array();
        /**
         * 尾部入对
         * @param [type] $value [description]
         */
        public function addLast($value){
            return array_push($this->queue,$value);
        }
        /**
         * 尾部出队
         * @return [type] [description]
         */
        public function removeLast(){
            return array_pop($this->queue);
        }
        /**
         * 头部入队
         * @param [type] $value [description]
         */
        public function addFirst($value){
            return array_unshift($this->queue, $value);
        }
        /**
         * 头部出队
         * @return [type] [description]
         */
        public function removeFirst(){
            return array_shift($this->queue);
        }
        /**
         * 清空队列
         * @return [type] [description]
         */
        public function makeEmpty(){
            unset($this->queue);
        }
        /**
         * 获取列头
         * @return [type] [description]
         */
        public function getFirst(){
            return reset($this->queue);
        }
        /**
         * 获取列尾
         * @return [type] [description]
         */
        public function getLast(){
            return end($this->queue);
        }
        /**
         * 获取长度
         * @return [type] [description]
         */
        public function getLength(){
            return count($this->queue);
        }
    }
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone. Learning is helpful. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to generate a short connection in php

##How to use PHP to duration based on seconds

The above is the detailed content of PHP two-way queue code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!