Description :
Deque stands for Double-ended queue.These are sequence containers with dynamic sizes that can be expanded or contracted on both ends.
Code:
#include<deque> //include deque library
#include<stdio.h>
#include<iostream.h>
using namespace std;
void main()
{
deque <int>dq;
deque <int>::iterator p;
char cc;
int val,ch;
do
{
cout<<”\n\nMENU:”;
cout<<”\n1. Enter element at front\n2. Enter element at Rear\n3. Delet element at front\n4. Delet element at Rear\n5. Disp front element\n6. Disp back element\n7. Display the element of Deque\n\n”;
cout<<”\nEnter choice:”;
cin>>ch;
switch(ch)
{
case 1:
cout<<”\n\nEnter the element to be inserted:”;
cin>>val;
dq.push_front(val);
cout<<”\nElement inserted at front:”<<dq.front();
break;
case 2:
cout<<”\n\nEnter the element to be inserted:”;
cin>>val;
dq.push_back(val);
cout<<”\nElement inserted at rear end:”<<dq.back();
break;
case 3:
cout<<”\nElementto be deleted at front:”<<dq.front();
dq.pop_front();
break;
case 4:
cout<<”\nElement to be deleted at rear:”<<dq.back();
dq.pop_back();
break;
case 5:
cout<<”\nElement at front:”<<dq.front();
break;
case 6:
cout<<”\nElement at rear:”<<dq.back();
break;
case 7:
if(dq.empty()==1)
cout<<”\n\nDEQUE is EMPTY..”;
else
{
cout<<”\n\nDisplaying the elements of DEQUE…\n”;
for(p=dq.begin();p<dq.end();p++)
cout<<” “<<*p<<”\t”;
}
break;
}
cout<<”\n\nCONTINUE MENU:”;
cin>>cc;
}while(cc==’y'); }
Deque stands for Double-ended queue.These are sequence containers with dynamic sizes that can be expanded or contracted on both ends.
Code:
#include<deque> //include deque library
#include<stdio.h>
#include<iostream.h>
using namespace std;
void main()
{
deque <int>dq;
deque <int>::iterator p;
char cc;
int val,ch;
do
{
cout<<”\n\nMENU:”;
cout<<”\n1. Enter element at front\n2. Enter element at Rear\n3. Delet element at front\n4. Delet element at Rear\n5. Disp front element\n6. Disp back element\n7. Display the element of Deque\n\n”;
cout<<”\nEnter choice:”;
cin>>ch;
switch(ch)
{
case 1:
cout<<”\n\nEnter the element to be inserted:”;
cin>>val;
dq.push_front(val);
cout<<”\nElement inserted at front:”<<dq.front();
break;
case 2:
cout<<”\n\nEnter the element to be inserted:”;
cin>>val;
dq.push_back(val);
cout<<”\nElement inserted at rear end:”<<dq.back();
break;
case 3:
cout<<”\nElementto be deleted at front:”<<dq.front();
dq.pop_front();
break;
case 4:
cout<<”\nElement to be deleted at rear:”<<dq.back();
dq.pop_back();
break;
case 5:
cout<<”\nElement at front:”<<dq.front();
break;
case 6:
cout<<”\nElement at rear:”<<dq.back();
break;
case 7:
if(dq.empty()==1)
cout<<”\n\nDEQUE is EMPTY..”;
else
{
cout<<”\n\nDisplaying the elements of DEQUE…\n”;
for(p=dq.begin();p<dq.end();p++)
cout<<” “<<*p<<”\t”;
}
break;
}
cout<<”\n\nCONTINUE MENU:”;
cin>>cc;
}while(cc==’y'); }
A branch of engineering called computer science engineering is concerned with the development, application, and administration of information systems. You can also check out about Best Colleges for CSE in India here.
ReplyDelete