Friday 24 November 2017

C++ Program to Implement Deque in STL


Code:

#include    iostream
#include    deque
#include    string
#include    cstdlib
using namespace std;
int main()
{
    deque dq;
    deque::iterator it;
    int choice, item;
    while (1)
    {
        cout<<"\n---------------------"<
        cout<<"Deque Implementation in Stl"<
        cout<<"\n---------------------"<
        cout<<"1.Insert Element at the End"<
        cout<<"2.Insert Element at the Front"<
cout<<"3.Delete Element at the End"<
        cout<<"4.Delete Element at the Front"<
        cout<<"5.Front Element at Deque"<
        cout<<"6.Last Element at Deque"<
        cout<<"7.Size of the Deque"<
        cout<<"8.Display Deque"<
        cout<<"9.Exit"<
        cout<<"Enter your Choice: ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            cout<<"Enter value to be inserted at the end: ";
            cin>>item;
            dq.push_back(item);
            break;
        case 2:
            cout<<"Enter value to be inserted at the front: ";
            cin>>item;
            dq.push_front(item);
            break;
        case 3:
            item = dq.back();
            dq.pop_back();
    cout<<"Element "<
            break;
        case 4:
            item = dq.front();
            dq.pop_front();
            cout<<"Element "<
            break;
        case 5:
            cout<<"Front Element of the Deque: ";
            cout<
            break;
        case 6:
            cout<<"Back Element of the Deque: ";
            cout<
            break;
        case 7:
            cout<<"Size of the Deque: "<
            break;
        case 8:
            cout<<"Elements of Deque:  ";
            for (it = dq.begin(); it != dq.end(); it++)
                cout<<*it<<"  ";
            cout<
            break;
        case 9:
            exit(1);
    break;
        default:
            cout<<"Wrong Choice"<
        }
    }
    return 0;
}


Output:

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 1
Enter value to be inserted at the end: 9

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 2
Enter value to be inserted at the front: 8

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 1
Enter value to be inserted at the end: 7

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 1
Enter value to be inserted at the end: 6

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 1
Enter value to be inserted at the end: 5

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 2
Enter value to be inserted at the front: 10

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 2
Enter value to be inserted at the front: 7

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 7
Size of the Deque: 7

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 8
Elements of Deque:  7  10  8  9  7  6  5  

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 5
Front Element of the Deque: 7

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 6
Back Element of the Deque: 5

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 3
Element 5 deleted

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 8
Elements of Deque:  7  10  8  9  7  6  

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 4
Element 7 deleted

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 7
Size of the Deque: 5

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 8
Elements of Deque:  10  8  9  7  6  

---------------------
Deque Implementation in Stl

---------------------
1.Insert Element at the End
2.Insert Element at the Front
3.Delete Element at the End
4.Delete Element at the Front
5.Front Element at Deque
6.Last Element at Deque
7.Size of the Deque
8.Display Deque
9.Exit
Enter your Choice: 9


------------------
(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...