Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Java equivalent of C++ deque?

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

like image 616
hongtaesuk Avatar asked Dec 02 '22 02:12

hongtaesuk


1 Answers

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.

like image 144
dsmith Avatar answered Dec 05 '22 16:12

dsmith