使用 SPL 中的 SplQueue 类
如果我们不想费时费力地实现队列功能,并对内置的解决方案感到满意,我们可以使用 SplQueue
类来满足我们对队列的基本需求。我们必须记住一点:SplQueue
类中没有可用的 peek
函数。我们必须使用 bottom()
函数来获取队列的第一个元素。下面是使用 SplQueue
为 AgentQueue
实现的简单队列:
Unresolved include directive in modules/ROOT/pages/ch04/ch4-08.adoc - include::example$Chapter04/7.php[]