I was trying to iterate over a STL stack in c++ but was unable to do so.
Is it even possible to iterate over a C++ STL Stack or Queue without popping(Like vectors)?
I was trying to iterate over a STL stack in c++ but was unable to do so.
Is it even possible to iterate over a C++ STL Stack or Queue without popping(Like vectors)?
No, you cannot iterate over a std::queue
since that is not its purpose.
A container that allows fast insertion at both ends, as well as iteration, is std::deque
. Note that iteration is slower than for a std::vector
, but insertion/removal at the beginning is much faster.