欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > php >内容正文

php

环形队列PHP,环形队列 - Go语言中文网 - Golang中文社区

发布时间:2025/4/16 php 24 豆豆
生活随笔 收集整理的这篇文章主要介绍了 环形队列PHP,环形队列 - Go语言中文网 - Golang中文社区 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

PHP代码实现

class Listo

{

public function getlist()

{

return $this->arr;

}

private $arr = array();

private $len = 0;

private $head = 0;

private $end = 0;

public function init($len){

$this->len = $len;

// 最后一个位置做区分用

for ($i=0; $i <= $len; $i++) {

$this->arr[$i] = null;

}

}

public function push($d){

$cur = $this->head;

if (++$this->head > $this->len ) {

$this->head = 0;

}

if ($this->head === $this->end) {

$this->head = $cur;

return null;

}

$this->arr[$cur] = $d;

}

public function pop()

{

if ($this->end === $this->head) {

return null;

}

$cur = $this->end;

if (++$this->end > $this->len ) {

$this->end = 0;

}

return $this->arr[$cur];

}

}

有疑问加站长微信联系(非本文作者))

《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读

总结

以上是生活随笔为你收集整理的环形队列PHP,环形队列 - Go语言中文网 - Golang中文社区的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。