+ 4

Why we need vector, queue, stack if we already have double ended queue in cpp ?

27th Sep 2021, 6:38 AM
Aditya Singh
Aditya Singh - avatar
12 Respuestas
+ 4
Well stack is also in STL. The difference between them is that in stack you have just push and pop(stack data structure) but dequeue is more like a vector, where u can go to any element of it or even insert().. basically you can use dequeue for anything u use stack for. It's just that some people find it easier and less confusing to use stack when you only need pop() and push()...
27th Sep 2021, 8:27 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
LIFO access is natural via a stack
27th Sep 2021, 10:33 PM
Sonic
Sonic - avatar
+ 1
STL dude we have dequeue<int>de; in dequeue we have both pop_front() and pop_back() , front() and back()
27th Sep 2021, 8:18 AM
Aditya Singh
Aditya Singh - avatar
+ 1
Mate STL is a library ;)
27th Sep 2021, 8:19 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Martin Taylor, yeah I totally know that... How is it different from what I said?
27th Sep 2021, 1:20 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Martin Taylor , right I've confused some things.... Thanks for explanation bro.
27th Sep 2021, 3:18 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
Mate, stack is a double ended queue... Not sure what u mean by "we already have double ended queue in CPP" but there is a std::<stack> header in C++.
27th Sep 2021, 8:16 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
And I'm asking about STL.
27th Sep 2021, 8:20 AM
Aditya Singh
Aditya Singh - avatar
0
Martin Taylor, queue might be both LIFO and FIFO. Stack is just one example of double ended queue. As you said double ended queue is not a stack but stack is a specific type of double ended queue....
27th Sep 2021, 9:09 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar