gpt4 book ai didi

java - Java Queue Implementation中pop如何在O(1)中执行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:23:35 24 4
gpt4 key购买 nike

我已阅读 here Java 的队列在 O(1) 中弹出。

We know that push and pop are constant time operations [O(1) to be precise (Do you know why?)].

我不明白的是 - 如何理解?如果它是一个链表,那么它就不能是 O(1),因为它必须保存最后一项。如果它是一个双向链表,那么它可以。但它是双向链表吗?

最佳答案

引用自 Java 7 API:

public class LinkedList extends AbstractSequentialList implements List, Deque, Cloneable, Serializable

Doubly-linked list implementation of the List and Deque interfaces. Implements all optional list operations, and permits all elements (including null).

所以是的,它是双向链接的。

关于java - Java Queue Implementation中pop如何在O(1)中执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24820026/

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