What does php two-way queue mean?

藏色散人
Release: 2023-03-13 15:18:01
Original
2287 people have browsed it

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); 
    }
    
}
Copy after login

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!

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!