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
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 of std::deque
, it does not provide the complexity guarantees that std::deque
does. In particular, std::deque
guarantees O(1)
lookup by index (random access), while LinkedList
has O(n)
lookup. In this sense (the sense in which an experienced C++ user views std::deque
), Java's LinkedList
is nothing at all like std::deque
(though it is very much like std::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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With