Computer Scientists are Pretty Pessimistic

Tuesday, 1 March 2016

Use of Stack in C++

#include <iostream>
#include <stack>
using namespace std;
int main ()
{
    stack<int>st;
    int val;
    for(int i=0;i<10;i++)
    {
        cin>>val;
        st.push(val);
    }
    while(!st.empty())
    {
        cout<<st.top()<<endl;
        st.pop();
    }
    return 0;
}

No comments:

Post a Comment