[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppStack
It can increase in size at run-time at one side (using push) and decrease is size (using pop). Only the top of the stack can be read (using top). Therefore, the std::stack has a LIFO ('last in, first out') structure.
resulting in the output:
A std::stack can be seen as a stripped-down std::vector/std::deque with only one side read/write-able.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppStack
(C++) std::stack
STL container class for storing values of any data type. Can be found in the header file stack.It can increase in size at run-time at one side (using push) and decrease is size (using pop). Only the top of the stack can be read (using top). Therefore, the std::stack has a LIFO ('last in, first out') structure.
int main() { std::stack<int> s; s.push(0); //First in s.push(1); s.push(2); //Last in std::cout << s.top() << std::endl; //Get the latest entry s.pop(); std::cout << s.top() << std::endl; s.pop(); std::cout << s.top() << std::endl; s.pop(); }
- include <iostream>
- include <stack>
resulting in the output:
2 1 0
A std::stack can be seen as a stripped-down std::vector/std::deque with only one side read/write-able.
Code links
Links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
