Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is faster: STL queue or STL stack?

I am implementing a variant of toposort, which needs a structure to hold elements with no incoming edges. Both queue and stack seem fine for this purpose, as the order in which they are taken out does not matter. The question is: is any of them significantly faster than the other?

like image 932
kinokijuf Avatar asked Nov 16 '25 21:11

kinokijuf


1 Answers

queue and stack are both container adaptors, not complete containers in their own right. Both stack and queue are implemented on top of a std::deque by default, they should have similar performance if you did not change this setup.

It really depends on what kind of application you are coding and you may select the underlying container which benefits those operations you want the most.

like image 184
taocp Avatar answered Nov 18 '25 11:11

taocp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!