Derconug Derconug - 3 months ago 14
C++ Question

Is there a function to add to the bottom of a c++ stack?

I could always use an array and write an algorithm for pushing items to the top but a stack would probably be more efficient and simpler to use later. I've searched for this function and couldn't find one.

Answer

Use a std::deque, which provides both std::deque::push_back and std::deque::push_front methods for pushing elements to the "top" and "bottom" of the data structure, respectively, in constant time.

Comments