C++ Stack
Stack- It follows last in first out(LIFO).
A push() function helps to insertion of a new element at the top of the stack.
A pop() function helps to the element in the stack is deleted from the front end.
Syntax:
template < class T, class Container = deque<T> > class stack;
Example:
#include <iostream> #include <stack> using namespace std; int main() { stack<int> s; int result=0; for (int j=1; j<=5; j++) s.push(j); while (!s.empty () ) { result += s.top (); s.pop(); } cout << "Result is: " << result; return 0; }
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.