Friday, 24 November 2017

C++ Program to Implement Stack in STL


Code:

#include    iostream
#include    stack
#include    string
#include    cstdlib
using namespace std;
int main()
{
    stack st;
    int choice, item;
    while (1)
    {
        cout<<"\n---------------------"<
        cout<<"Stack Implementation in Stl"<
        cout<<"\n---------------------"<
        cout<<"1.Insert Element into the Stack"<
        cout<<"2.Delete Element from the Stack"<
cout<<"3.Size of the Stack"<
        cout<<"4.Top Element of the Stack"<
        cout<<"5.Exit"<
        cout<<"Enter your Choice: ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            cout<<"Enter value to be inserted: ";
            cin>>item;
            st.push(item);
            break;
        case 2:
            item = st.top();
            st.pop();
    cout<<"Element "<
            break;
        case 3:
    cout<<"Size of the Queue: ";
    cout<
            break;
        case 4:
    cout<<"Top Element of the Stack: ";
    cout<
            break;
        case 5:
            exit(1);
    break;
        default:
            cout<<"Wrong Choice"<
        }
    }
    return 0;
}


Output:

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 1
Enter value to be inserted: 2

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 1
Enter value to be inserted: 3

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 1
Enter value to be inserted: 4

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 1
Enter value to be inserted: 5

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 1
Enter value to be inserted: 6

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 4
Top Element of the Stack: 6

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 3
Size of the Queue: 5

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 2
Element 6 Deleted

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 4
Top Element of the Stack: 5

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 3
Size of the Queue: 4

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 1
Enter value to be inserted: 8

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 4
Top Element of the Stack: 8

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 3
Size of the Queue: 5

---------------------
Stack Implementation in Stl

---------------------
1.Insert Element into the Stack
2.Delete Element from the Stack
3.Size of the Stack
4.Top Element of the Stack
5.Exit
Enter your Choice: 5


------------------
(program exited with code: 1)
Press return to continue



More C++ Programs:
















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...