Sunday, September 22, 2013

Shortest Program to perform Stack Operations Using () Header File.


**This program may not run on Older Versions of GCC. Use 4.8.1 GCC Compiler to run this program.



#include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;
int main()
{
    stack<int> s;
    int ch,n;
    cout<<"\n \t\t STACK OPERATIONS \n\n 1.PUSH \t2.POP\t 3.DISPLAY\t4.EXIT.\n\n Enter Your Choice::";
    cin>>ch;
    switch(ch)
    {
    case 1:cout<<"\n Element::";cin>>n;s.emplace(n);main();break;
    case 2:s.pop();main();break;
    case 3:for(int i=0;i<s.size();i++)
                 cout<<"\n"<<s.top();
           main();break;
    case 4:exit(0);
    default:cout<<"\n\t\n Wrong Choice !!";
            main();break;
    }
    return 0;
}

No comments:

Post a Comment