What would you rather choose to implement deque: HashSet or LinkedList. And could you state cons and pros for both please? Thank you.
+2
A:
A HashSet
is not a Deque
so you would have to use a LinkedList
(which does implement Deque
). The reason behind this is that HashSet
is not an ordered data structure, and hence cannot be used as a queue.
For thread-safe blocking implementations of Deque
consider LinkedBlockingDeque
or ArrayDeque
.
Adamski
2010-03-29 13:18:40
+2
A:
Of course LinkedList. All Dequeue operations there are implemented strictly as O(1) and no excessive memory is used.
Andrey
2010-03-29 13:20:48