Home  >  Article  >  Backend Development  >  What does php two-way queue mean?

What does php two-way queue mean?

藏色散人
藏色散人Original
2021-10-29 10:45:482304browse

php Bidirectional queue refers to a data structure with the properties of queue and stack; elements in the bidirectional queue can be popped from both ends, and it limits insertion and deletion operations to be performed at both ends of the table; bidirectional queue Like a queue, but you can add or remove elements at either end.

What does php two-way queue mean?

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

What does php bidirectional queue mean?

PHP - Use PHP to implement a two-way queue

1. Introduction

deque, the full name is double-ended queue, is a A data structure that has properties of queues and stacks. Elements in a double-ended queue can be popped from both ends, and insertion and deletion operations are limited to both ends of the table. A deque (double-ended queue) is like a queue, but you can add or remove elements from either end.

Reference: http://zh.wikipedia.org/zh-cn/Double-Ended Queue

2.PHP implementation code

<?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); 
    }
    
}

Recommended study: " PHP video tutorial

The above is the detailed content of What does php two-way queue mean?. 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