gpt4 book ai didi

java - 收集队列

转载 作者:行者123 更新时间:2023-12-01 19:22:18 25 4
gpt4 key购买 nike

如果我想自定义队列的实现,正确的是说我可以选择我想要的任何顺序(不是 FIFO),但我必须始终尊重要删除的元素定位为“head”的事实吗?

但对于插入操作,我没有义务将元素放在尾部(例如放入 FIFO 中)?

最佳答案

你是对的。 javadoc明确指出这一点:

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner. Among the exceptions are priority queues, which order elements according to a supplied comparator, or the elements' natural ordering, and LIFO queues (or stacks) which order the elements LIFO (last-in-first-out). Whatever the ordering used, the head of the queue is that element which would be removed by a call to remove() or poll(). In a FIFO queue, all new elements are inserted at the tail of the queue. Other kinds of queues may use different placement rules. Every Queue implementation must specify its ordering properties.

关于java - 收集队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3522424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com