Write a program in c++ to implement the stack push 5 values (10,20,30,40,50,)in the stack them pops value and display the remaining stack value.
//Stack working based LIFO-Last Input First Output
/*
For example
Add to stack 10
stack=[10]
Add to stack 20
stack=[10,20]
Pop to stack
stack=[20]
.........
*/
#include <iostream>
#include <iomanip>
#include <stack>//USE standart Stack
using namespace std;
int main()
{
stack<int>st;
int start=10;
while(start<=50)//push 10 20 30 40 50
{
st.push(start);
cout<<"Add to stack number:->"<<start<<endl;
start+=10;
}
//print all item (LIFO -style)
while(!st.empty())
{
cout<<setw(5)<<st.top()<<" ";
st.pop();
}
return 0;
}
//This code testing on Lunix online compiler
Comments
Leave a comment