php 数据结构之链表队列
2020-02-20
发布者:金俊明
导读队列是先进先出的线性表,它只允许在表的前端删除和在表的后端插入,下面爱站技术频道小编就来为大家分析php 数据结构之链表队列,希望能帮到您。php 链表队列 实例代码:class Queue{ private $last; private $firs
队列是先进先出的线性表,它只允许在表的前端删除和在表的后端插入,下面爱站技术频道小编就来为大家分析php 数据结构之链表队列,希望能帮到您。
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;
php 数据结构之链表队列,大家都清楚吗?当然,学习的方法多种多样,大家想要继续了解的话,可以关注js.aizhan.com吧!
原文链接:https://js.aizhan.com/develop/php/11642.html
如有疑问请与原作者联系
免责声明:本文章由会员“金俊明”发布如果文章侵权,请联系我们处理,本站仅提供信息存储空间服务如因作品内容、版权和其他问题请于本站联系
上一篇:个体营业执照不好办理商标注册吗
下一篇:PHP实现的贪婪算法实例