Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a implementation of a Double ended Queue #1271

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 81 additions & 0 deletions data_structures/Double_Ended_Queue.cpp
@@ -0,0 +1,81 @@
/*Author Alok Khulbay
Date:12/10/2020.
*/
#include <iostream>
#include <deque>
#include <string>
#include <cstdlib>
#include <conio.h>
using namespace std;
int main()
{
deque<int> d;
deque<int>::iterator it;
int c, item;
while (1)
{
cout << "1.Size of the Deque" << endl;
cout << "2.Insert Element at the End" << endl;
cout << "3.Insert Element at the Front" << endl;
cout << "4.Delete Element at the End" << endl;
cout << "5.Delete Element at the Front" << endl;
cout << "6.Front Element at the Deque" << endl;
cout << "7.Last Element at the Deque" << endl;
cout << "8.Display Deque" << endl;
cout << "9.Exit" << endl;
cout << "Enter your choice:";
cin >> c;
switch (c)
{
case 1:
cout << "Size of the Deque: " << d.size() << endl;
break;
case 2:
cout << "Enter value to be inserted at the End: " << endl;
cin >> item;
d.push_back(item);
break;
case 3:
cout << "Enter value to be inserted at the Front: " << endl;
cin >> item;
d.push_front(item);
break;
case 4:
item = d.back();
d.pop_back();
cout << "Element " << item << " Deleted" << endl;
break;
case 5:
item = d.front();
d.pop_front();
cout << "Element " << item << "Deleted" << endl;
break;
case 6:
cout << "Front Element of the Deque is: ";
cout << d.front() << endl;
break;
case 7:
cout << "Back Element of the Deque is: ";
cout << d.back() << endl;
break;
case 8:
cout << "Elements of Deque: ";
for (it = d.begin(); it != d.end(); it++)
{
cout << *it << " ";
cout << endl;
}
break;
case 9:
exit(1);
break;

default:
cout << "Wrong Choice" << endl;
}
cout << "Press any key>>>>>>" << endl;
getchar();
getche();
}
return 0;
}