/*
Problem statement:
Write C++ program using STL for Dqueue (Double ended queue)
*/
#include<iostream>
#include<deque>
using namespace std;
int main()
{
int element,ch;
char ans;
deque <int> de;
deque <int>::iterator itre;
do
{
cout<<"**************Deque*******************\n";
cout<<"Which operations do you which to perform:\n";
cout<<"1.Insert an element at front\n";
cout<<"2.Insert an element at back\n";
cout<<"3.Pop an element from front\n";
cout<<"4.Pop an element from back\n";
cout<<"5.Size\n";
cout<<"6.Empty\n";
cout<<"7.Display\n";
cout<<"Enter your choice\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter an element\n";
cin>>element;
de.push_front(element);
break;
case 2:
cout<<"Enter an element\n";
cin>>element;
de.push_back(element);
break;
case 3:
element=de.front();
de.pop_front();
cout<<element<<" was successfully poped from front\n";
break;
case 4:
element=de.back();
de.pop_back();
cout<<element<<" was successfully poped from back\n";
break;
case 5:
element=de.size();
cout<<"Size of deque is\t"<<element;
break;
case 6:
if(de.empty())
{
cout<<"\nDeque is empty\n";
}
else
{
cout<<"\nDeque is not empty\n";
}
break;
case 7:
cout<<"\nDeque is\n";
for(itre=de.begin();itre!=de.end();itre++)
{
cout<<*itre<<endl;
}
break;
default:
cout<<"Sorry bad choice!!!!!!";
break;
}
cout<<"\nDo you wish to continue? (Y/N)\n";
cin>>ans;
}while(ans=='Y');
}
/*
Output:
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
1
Enter an element
1
Do you wish to continue? (Y/N)
Y
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
2
Enter an element
2
Do you wish to continue? (Y/N)
Y
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
3
1 was successfully poped from front
Do you wish to continue? (Y/N)
Y
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
4
2 was successfully poped from back
Do you wish to continue? (Y/N)
Y
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
5
Size of deque is 0
Do you wish to continue? (Y/N)
Y
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
1
Enter an element
4
Do you wish to continue? (Y/N)
Y
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
6
Deque is not empty
Do you wish to continue? (Y/N)
Y
**************Deque*******************
Which operations do you which to perform:
1.Insert an element at front
2.Insert an element at back
3.Pop an element from front
4.Pop an element from back
5.Size
6.Empty
7.Display
Enter your choice
7
Deque is
4
Do you wish to continue? (Y/N)
N
*/
0 Comments