PHP code to implement two-way queue

小云云
Release: 2023-03-21 18:56:01
Original
1389 people have browsed it

This article shares with you a small piece of code, which is about the code for implementing two-way queue in PHP. I hope it can help you.

<?phpclass Deque {

    private $queue = array();    public function addFirst($item) {
        return array_unshift($this->queue, $item);
    }    public function addLast($item) {
        return array_push($this->queue, $item);
    }    public function removeFirst() {
        return array_shift($this->queue);
    }    public function removeLast() {
        return array_pop($this->queue);
    }

}
Copy after login

Related recommendations:

Example of php implementing two-way queue

Detailed introduction to two-way queue

How to use php to implement a two-way queue code example

The above is the detailed content of PHP code to implement two-way queue. 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!