Skip to content

Instantly share code, notes, and snippets.

@tanvir002700
Created April 16, 2016 09:21
Show Gist options
  • Save tanvir002700/0bd0a42a4140f6e400810534b5714e40 to your computer and use it in GitHub Desktop.
Save tanvir002700/0bd0a42a4140f6e400810534b5714e40 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<stack>
#include<stdlib.h>
using namespace std;
int main()
{
stack<int>S;
for(int i=0;i<5;i++)
{
int x=rand()%100;
cout<<"Push: "<<x<<endl;
S.push(x);
}
cout<<"Stack size: "<<S.size()<<endl;
cout<<"Top element: "<<S.top()<<endl;
S.pop();
cout<<"After pop top element: "<<S.top()<<endl;
while(!S.empty())S.pop();
cout<<"Is stack empty: "<<S.empty()<<endl;
return 0;
}
Push: 83
Push: 86
Push: 77
Push: 15
Push: 93
Stack size: 5
Top element: 93
After pop top element: 15
Is stack empty: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment