Home >Backend Development >PHP Tutorial >PHP code implements two-way queue

PHP code implements two-way queue

小云云
小云云Original
2018-03-21 15:34:051577browse

This article mainly shares with you the php code to implement a two-way queue. It is mainly shared with you in the form of code. 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);
    }
}

Related recommendations:

php code to implement two-way queue

Detailed introduction to two-way queue

php Two-way queue class

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

Statement:
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