Write C++ program using STL for Dqueue (Double ended queue)

/*
Write C++ program using STL for Dqueue (Double ended queue)
*/
#include<iostream>
#include<deque>
using namespace std;
int main()
{
    int x;
    char ans;
    int ch;
   
    deque<int>dq;
    deque<int>::iterator i;
    do{
        cout<<"\nMain Menu";
        cout<<"\n1.Insert from rear";
        cout<<"\n2.Insert from front";
        cout<<"\n3.Delete front";
        cout<<"\n4.Delete rear";
        cout<<"\n5.Size of deque";
        cout<<"\n6.Display elements";
        cout<<"\n0.Exit";
        cout<<"\nEnter the choice:";
        cin>>ch;
       
        switch(ch)
        {
            case 1:
                cout<<"\nEnter element:";
                cin>>x;
                dq.push_back(x);
                break;
               
            case 2:
                cout<<"\nEnter element:";
                cin>>x;
                dq.push_front(x);
                break;
               
            case 3:
                x=dq.front();
                dq.pop_front();
                cout<<"\nDeleted "<<x;
                break;
               
            case 4:
                x=dq.back();
                dq.pop_back();
                cout<<"\nDeleted "<<x;
                break;
               
            case 5:
                cout<<"\nSize of deque:"<<dq.size();
                break;
               
            case 6:
                cout<<"Elements of deque are:\n";
                for(i=dq.begin();i!=dq.end();i++)
                cout<<*i<<" ";
                break;
               
            case 0:
                cout<<"\nExit\n";
                break;
        }
    }while(ch!=0);
}

Comments

Popular posts from this blog

Operator Overloading (complex number) using c++

class template to represent a generic vector using c++

Write a menu driven program that will create a data file containing the list of telephoneUse a class object to store each set of data, access the file created and implement the following tasks Determine the telephone number of specified person Determine the name if telephone number is known Update the telephone number, whenever there is a change.