![](/style/images/good.png)
![](/style/images/bad.png)
PHP之队列-Queue
source link: https://panda843.github.io/article/1490765381.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
PHP之队列-Queue
SPL,PHP 标准库(Standard PHP Library) ,从 PHP 5.0 起内置的组件和接口,且从 PHP5.3 已逐渐的成熟。SPL 在所有的 PHP5 开发环境中被内置,同时无需任何设置。
队列原理图
SplQueue
队列是一种先进先出(FIFO)的数据结构。使用队列时插入在一端进行而删除在另一端进行。
PHP SPL中的SplQueue也是继承自SplDoublyLinkedList,并有自己的方法
SplQueue类说明
SplQueue extends SplDoublyLinkedList implements Iterator , ArrayAccess , Countable { |
SplQueue使用
<?php |
SplPriorityQueue
优先级队列是不同于先进先出队列的另一种队列,它每次从队列中取出的是具有最高优先权的元素, 这里的优先是指元素的某一属性优先,以比较为例,可能是较大的优先,也可能是较小的优先。 PHP实现的优先级队列默认是以大头堆实现,即较大的优先,如果要较小的优先,则需要继承SplPriorityQueue类,并重载compare方法。
PHP SPL中的SplPriorityQueue是基于堆实现的。和堆一样,也有int compare ( mixed $priority1 , mixed $priority2 )方法。
SplPriorityQueue实现了Iterator,Countable接口
SplPriorityQueue类说明
SplPriorityQueue implements Iterator , Countable { |
SplPriorityQueue使用
$pq = new SplPriorityQueue(); |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK