Answer to Question #332730 in C++ for Pink

Question #332730

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.


1
Expert's answer
2022-04-23T09:04:26-0400


//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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS