What is that where deque is the life saver | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is that where deque is the life saver

Hi All When we have requirement to access values randomly rather than iterating one by one, vector is the best option.. For operation like sequences in original order it was provided , queue helps us... Example is processing instructions in provided order. When we just want to reverse something , stack is handy. Example is to reverse the string.. Is above true? Query is about deque. What is it's use case? Opting other than deque will be costlier in which case ?

7th Jun 2020, 4:28 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
4 Answers
+ 4
As far as I know,there is no special case where a deque is preferable.In all scenarios there is always a container that outperforms a deque
7th Jun 2020, 7:33 PM
Anthony Maina
Anthony Maina - avatar
+ 3
A deque is a doubly-ended queue,meaning that unlike a queue you can access(read and write) both of its ends. For its use case,well,it might come as a surprise to many,but queues and stacks use deques as their underlying container. However I don't actually recommend using it as a container since there is always a better alternative in all given scenarios.Its better to just leave it as an implementation detail of the two above classes.
7th Jun 2020, 7:16 PM
Anthony Maina
Anthony Maina - avatar
0
Yes a surprise Anthony Maina ...I thought array or linked list as implementation for queue and stack... I understand what we can do on deque but looking for some use case.. is it just for implementing queue and stack ? It's difficult to digest as if so, that might not be available to us as seperate entity
7th Jun 2020, 7:27 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
7th Jun 2020, 7:37 PM
Ketan Lalcheta
Ketan Lalcheta - avatar