php 數(shù)據(jù)結(jié)構(gòu)之鏈表隊列
更新時間:2017年10月17日 14:18:24 作者:xingjigongsi
這篇文章主要介紹了php 數(shù)據(jù)結(jié)構(gòu)之鏈表隊列的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
php 鏈表隊列
實例代碼:
class Queue{ private $last; private $first; private $oldfirst; private static $n=0; public function __construct(){ $this->last = null; $this->first = null; $this->oldfirst = null; } public function push($item){ $this->oldfirst = $this->last; $this->last = new Node(); $this->last->item = $item; $this->last->next = null; if(empty($this->first)){ $this->first = $this->last; }else{ $this->oldfirst->next = $this->last; } self::$n++; } public function pop(){ if(self::$n<0){ return null; } $item = $this->first->item; $this->first = $this->first->next; self::$n--; return $item; } } class Node{ public $item; public $next; } $Queue = new Queue(); $Queue->push("a"); $Queue->push("b"); $Queue->push("c"); echo $Queue->pop().PHP_EOL; echo $Queue->pop().PHP_EOL; echo $Queue->pop().PHP_EOL; echo $Queue->pop().PHP_EOL;
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
PHP使用array_multisort對多個數(shù)組或多維數(shù)組進(jìn)行排序
這篇文章主要介紹了PHP使用array_multisort對多個數(shù)組或多維數(shù)組進(jìn)行排序,需要的朋友可以參考下2014-12-12Yii2增刪改查之查詢 where參數(shù)詳細(xì)介紹
這篇文章主要介紹了Yii2增刪改查之查詢 where參數(shù)詳細(xì)介紹的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08