Is it possible to traverse std::stack
in C++?
Traversing using following method is not applicable. Because std::stack
has no member end
.
std::stack<int> foo; // .. for (__typeof(foo.begin()) it = foo.begin(); it != foo.end(); it++) { // ... }
Is it possible to traverse std::stack in C++?
No. A stack is a data structure you should use when you are interested in placing elements on top and getting elements from the top. If you want an iterable stack, either use a different data structure for a stack role (std::vector
?) or write one yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With