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

Write a function template selection Sort. Write a program that inputs, sorts and outputs an integer array and a float array.

C++ program that creates an output file, writes information to it, closes the file and open it again as an input file and read the information from the file.

Write C++ program using STL for Sorting and searching