Java 中 C++ 的等价物是什么?双端队列?
在 C++ 中我所要做的就是
#include <queue> -> including
queue<int> a; -> defining
a.push(1); ->using
但在 java 中我发现使用简单的双端队列非常困难 我应该怎么办...? 更具体地说, 我应该如何编码来简单地执行相同的步骤 就像我在 C++ 中所做的那样;包括、定义、使用。
更具体地说, 我想做一个双端队列,这样我就可以 在双端队列的前面或后面添加任何整数。 并按双端队列的大小打印该双端队列中的整数
in C++ all I had to do was
#include <queue> -> including
queue<int> a; -> defining
a.push(1); ->using
but in java I found very difficult to use simple deque
what should I do...?
more specifically,
How should I code to simply do the same steps
as I did in C++; including, defining, using.
even more specifically,
I want to make a deque so that I can
add any integer in the deque at front or back.
and print whole numbers in that deque by the size of the deque
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当前的答案表明Java的 java.util.LinkedList< /a> 是 C++ 的 std::deque 的 Java 翻译。虽然
LinkedList
确实有一个大致相当于std::deque
的接口,但它没有提供std::deque
的复杂性保证> 确实如此。特别是,std::deque
保证通过索引进行O(1)
查找(随机访问),而LinkedList
具有O(n )
查找。从这个意义上(经验丰富的 C++ 用户查看std::deque
的意义上来说),Java 的LinkedList
与std::deque
完全不同> (尽管它非常类似于std::list
)。 此线程为“什么是 Java 等价物”这个问题提供了更好的答案C++ 双端队列”。总而言之,标准 Java 库中没有等效的库。The current answers suggest that Java's java.util.LinkedList is the Java translation of C++'s std::deque. While
LinkedList
does have an interface that is roughly equivalent to that ofstd::deque
, it does not provide the complexity guarantees thatstd::deque
does. In particular,std::deque
guaranteesO(1)
lookup by index (random access), whileLinkedList
hasO(n)
lookup. In this sense (the sense in which an experienced C++ user viewsstd::deque
), Java'sLinkedList
is nothing at all likestd::deque
(though it is very much likestd::list
). This thread provides a better answer to the question "What is is the Java equivalent of C++ deque". To sum up, there is no equivalent in the standard Java library.Java 同时具有 Queue 和 Deque 类型,以及一个 LinkedList 等可以充当以下任一者:
Java has both Queue and Deque types, and a LinkedList, among others, can act as either one:
查看 java.util.LinkedList。
Look at java.util.LinkedList.