日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2025/4/16 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 环形队列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中文社区的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。