当前位置:网站首页>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());

边栏推荐
- Vivado error code [drc pdcn-2721] resolution
- Beifu PLC model selection -- how to see whether the motor is a multi turn absolute value encoder or a single turn absolute value encoder
- J - Wooden Sticks poj 1065
- scrapy——爬取漫画自定义存储路径下载到本地
- [how to connect the network] Chapter 2 (next): receiving a network packet
- Echart stack histogram: add white spacing effect setting between color blocks
- Enjoy element mode (flyweight)
- UVA10341 solve it 二分
- Chapter 10 setting up structured logging (2)
- Reflect the technical depth (unable to speed up)
猜你喜欢

Opencv high speed download

Processing function translate (mousex, mousey) learning

12 SQL optimization schemes summarized by old drivers (very practical)

Machine learning notes - seasonality of time series

Here Document免交互及Expect自动化交互

橋接模式(Bridge)
![8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)](/img/e7/2fd8ec8d5e5473c7f84f3e3bcedca8.png)
8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)

Beifu cx5130 card replacement and transfer of existing authorization files

Do you know the limitations of automated testing?

Fire warning is completed within 10 seconds, and Baidu AI Cloud helps Kunming Guandu build a new benchmark of smart city
随机推荐
First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology
Mysql database explanation (V)
Word document export (using fixed template)
HDU 5860
SQL assigns the field value of data table B to a column in data table a
Go structure method
mysql讲解(一)
MySQL explanation (I)
Solutions to insufficient display permissions of find and Du -sh
I - Dollar Dayz
ES6:Map
利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
首批通过!百度智能云曦灵平台获信通院数字人能力评测权威认证
Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏
D - skiing
Nlp-d60-nlp competition D29
Log in to the server using SSH key pair
Processing random generation line animation
HDU 3709 Balanced Number
Uva11582 [fast power]colossal Fibonacci numbers!