//basic stack stl c++
#include<iostream>
#include<stack>
using namespace std;
void display(stack<int> s)
{
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
cout<<endl;
}
int main()
{
stack<int> s;
s.push(1);
s.push(4);
s.push(5);
display(s); //display the stack elements
s.pop(); //removes the top element
display(s);
if(s.empty())
cout<<"The stack is empty"<<endl;
else
cout<<"stack is not empty"<<endl;
return 0;
}
#include<iostream>
#include<stack>
using namespace std;
void display(stack<int> s)
{
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
cout<<endl;
}
int main()
{
stack<int> s;
s.push(1);
s.push(4);
s.push(5);
display(s); //display the stack elements
s.pop(); //removes the top element
display(s);
if(s.empty())
cout<<"The stack is empty"<<endl;
else
cout<<"stack is not empty"<<endl;
return 0;
}
Comments
Post a Comment