当前位置:网站首页>Ring queue PHP
Ring queue PHP
2022-06-26 13:21:00 【liuliang514218119】
<?php
# The circular queue php
class queue
{
public $queue = [];
public $size;
public $front = 0; # Pointer to the first team
public $rear = 0; # Pointer to a party
public function __construct($size = 10)
{
$this->size = $size;
for ($i = 0; $i < $this->size; $i++) {
$this->queue[] = '';
}
}
# List
public function push($element)
{
if (!$this->is_filled()) {
$this->rear = ($this->rear + 1) % $this->size;
$this->queue[$this->rear] = $element;
} else {
throw new Exception(" The queue is full ");
}
}
# List out
public function pop()
{
if (!$this->is_empty()) {
$this->front = ($this->front + 1) % $this->size;
$element = $this->queue[$this->front];
$this->queue[$this->front] = '';
return $element;
} else {
throw new Exception(" The queue is empty ");
}
}
# Determines if the queue is empty
public function is_empty()
{
return $this->rear == $this->front;
}
# Determine whether the queue is full
public function is_filled()
{
return ($this->rear + 1) % $this->size == $this->front;
}
public function get_queue()
{
return $this->queue;
}
}
// Declaration stack
$queue = new queue(6);
$queue->push(5);
$queue->push(6);
$queue->push(7);
$queue->push(8);
$queue->push(9);
$queue->pop();
$queue->pop();
$queue->pop();
$queue->push(10);
$queue->push(11);
$queue->push(12);
print_r($queue->get_queue());

边栏推荐
- 解中小企业之困,百度智能云打个样
- Script - crawl the customized storage path of the cartoon and download it to the local
- Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏
- I have a good word to say, and I admire myself
- Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller
- Explain C language 11 in detail (C language series)
- Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
- Reflect the technical depth (unable to speed up)
- What are the common categories of software testing?
- Electron official docs series: References
猜你喜欢

What features are added to Photoshop 2022 23.4.1? Do you know anything

Explain C language 11 in detail (C language series)

To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example
![Vivado error code [drc pdcn-2721] resolution](/img/de/ce1a72f072254ae227fdcb307641a2.png)
Vivado error code [drc pdcn-2721] resolution

IDC报告:百度智能云AI Cloud市场份额连续六次第一

What are the common categories of software testing?

2、并行接口、协议和相关芯片介绍(8080、8060)

First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology

Analysis of state transition diagram of Beifu NC axis

MySQL explanation (II)
随机推荐
HDU1724[辛普森公式求积分]Ellipse
Beifu PLC realizes zero point power-off hold of absolute value encoder -- use of bias
8、【STM32】定时器(TIM)——中断、PWM、输入捕获实验(一文精通定时器)
Nlp-d60-nlp competition D29
J - Wooden Sticks poj 1065
Hdu1724[Simpson formula for integral]ellipse
利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
IDC报告:百度智能云AI Cloud市场份额连续六次第一
shell脚本详细介绍(四)
H5 video automatic playback and circular playback
Digital signal processing -- Design of linear phase type (Ⅰ, Ⅲ) FIR filter (1)
Bigint: handles large numbers (integers of any length)
POJ 3070 Fibonacci
Common creation and usage of singletons
Mode pont
MySQL数据库讲解(四)
Aesthetic experience (episode 238) Luo Guozheng
H - Sumsets POJ 2229
SQL assigns the field value of data table B to a column in data table a
Uva5009 error curves three points