Stacks are a type of container adaptors with LIFO(Last In First Out) type of working. The element that is pushed at the end is popped out first. Push an element into the stack. Removes the element by following the LIFO order. Returns the element present at the top of the stack. Returns whether the stack is empty or not.
The program demonstrates the use of the STL Stack container in C++.
#include<iostream> #include<stack> using namespace std; //STL-Stack in C++ void print(stack<int> x) { while (!x.empty()) { cout <<" " << x.top(); x.pop(); } cout<<endl; } int main() { stack<int> s; s.push(10); s.push(20); s.push(30); s.push(40); cout<<"Empty or Not : "<<s.empty()<<endl; cout<<"Size: "<<s.size()<<endl; print(s); s.pop(); print(s); return 0; }
Empty or Not : 0 Size: 4 40 30 20 10 30 20 10To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions