You are on page 1of 3

PROGRAM 1

#include <iostream>

#include <stack>

using namespace std;

int main ()

stack<int>s1;

s1.push(10);

s1.push(20);

stack<int> s;

s.push(2);

s.push(3);

s.push(4);

s.pop();

cout << s.top()<<endl;

cout << s.size()<<endl;

swap(s,s1);

while(!s.empty())

cout<<s.top()<<endl;

s.pop();

while(!s1.empty())

cout<<s1.top()<<endl;
s1.pop();

PROGRAM 2

#include <iostream>

#include <stack>

using namespace std;

int main()

stack<int> nStack;

cout<<"The size is="<<nStack.size()<<endl;

nStack.push(1);

nStack.push(2);

stack<int> nStack1;

nStack1.push(3);

nStack1.push(4);

//nStack.swap(nStack1);

cout<<"After pushing "<<endl;

cout<<"The size is="<<nStack.size()<<endl;

int nElement =nStack.top();

//cout<<"The size is="<<nStack.size()<<endl;

cout<<"The top element is"<<nElement<<endl;

cout<<"Stack Elements are"<<endl;

while(!nStack.empty())

{
cout<<nStack.top()<<endl;

nStack.pop();

cout<<"After Popping"<<endl;

cout<<"The size is="<<nStack.size()<<endl;

nStack.pop();

return 0;

You might also like