A deque (pronounced deck) is an ordered set of items from which items may be deleted at either
end and into which items may be inserted at either end. Call the two ends left and right. This is
an access-restricted structure since no insertions or deletions can happen other than at the ends.
Implement a deque as a doubly-linked circular list with a header. Write InsertRight and
DeleteLeft.
Solution
code:
#include
using namespace std;
class Node
{
public:
int data;
Node* next;
Node* prev;
};
class Deque
{
private:
Node* front;
Node* rear;
int count;
public:
Deque()
{
front = NULL;
rear = NULL;
count = 0;
}
bool isEmpty()
{
if(count == 0)
return true;
else
return false;
}
int DeleteLeft()
{
if ( isEmpty() ) {
cout<<"deque is empty... can't delete'";
return -1;
}
int ret = front->data;
Node* tmp = front;
if ( front->next != NULL )
{
front = front->next;
front->prev = NULL;
}
else
{
front = NULL;
}
count--;
delete tmp;
return ret;
}
void InsertRight(int element)
{
Node* tmp = new Node();
tmp->data = element;
tmp->next = NULL;
tmp->prev = NULL;
if ( isEmpty() ) {
front = rear = tmp;
}
else {
rear->next = tmp;
tmp->prev = rear;
rear = tmp;
}
count++;
}
};
int main()
{
Deque q;
if ( q.isEmpty() )
{
cout << "Deque is empty" << endl;
}
q.InsertRight(100);
q.InsertRight(200);
q.InsertRight(300);
Deque q1;
if ( q1.isEmpty() )
{
cout << "Deque is empty" << endl;
}
q1.InsertRight(100);
q1.InsertRight(200);
q1.InsertRight(300);
cout << q1.DeleteLeft() << endl;
cout << q1.DeleteLeft() << endl;
cout << q1.DeleteLeft() << endl;
}

More Related Content

PDF
JAVA A double-ended queue is a list that allows the addition and.pdf
PPTX
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
DOCX
What is Linked List in C.docx
PDF
How to delete one specific node in linked list in CThanksSolu.pdf
PPTX
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
PDF
Unit - 2.pdf
PPT
Link list part 2
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
What is Linked List in C.docx
How to delete one specific node in linked list in CThanksSolu.pdf
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
Unit - 2.pdf
Link list part 2
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf

Similar to A deque (pronounced deck) is an ordered set of items from which item.pdf (20)

PDF
Write a program to implement below operations with both singly and d.pdf
PDF
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
PPTX
linkedlist.pptx
PPTX
C Exam Help
PPTX
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
PDF
Using the provided table interface table.h and the sample linked lis.pdf
PPT
linkedLists.ppt
PPT
Introduction to linked Lists in data structure.ppt
PPT
linkedLists.ppt presentation on the topic
PDF
In java , I want you to implement a Data Structure known as a Doubly.pdf
PDF
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
PDF
How do you stop infinite loop Because I believe that it is making a.pdf
PDF
This is a c++ binary search program I worked so far but still cant g.pdf
PPTX
DSA(1).pptx
PPTX
Lecture11 standard template-library
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
PDF
PDF
How to build a Linked List that can insert any type of data. For exa.pdf
PPTX
C Homework Help
Write a program to implement below operations with both singly and d.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
linkedlist.pptx
C Exam Help
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Using the provided table interface table.h and the sample linked lis.pdf
linkedLists.ppt
Introduction to linked Lists in data structure.ppt
linkedLists.ppt presentation on the topic
In java , I want you to implement a Data Structure known as a Doubly.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
DSA(1).pptx
Lecture11 standard template-library
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
How to build a Linked List that can insert any type of data. For exa.pdf
C Homework Help
Ad

More from hardjasonoco14599 (20)

PDF
[Quantum Mechanics] In my class we are talking about the quantum har.pdf
PDF
Write a function which return a list of all of the n element subset .pdf
PDF
what is tax preferenceSolutionTax preferences are measures of .pdf
PDF
Which of the following is true regarding homologous structuresA. .pdf
PDF
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdf
PDF
Which of the following is NOT a complication in development of an HIV.pdf
PDF
Write a C++ program that implements a binary search tree (BST) to man.pdf
PDF
Which of the following groups is responsible for the actual developm.pdf
PDF
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdf
PDF
what does it takes to be a living organ What does it take to be a l.pdf
PDF
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
PDF
This one is for you - assume that this pedigree shows the inheritance.pdf
PDF
There are 7 people in the elevator in a 10-story building. They are .pdf
PDF
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
PDF
Question 1 A ____________ is an intelligent device that controls the.pdf
PDF
I finished most of the program, but having trouble with some key fea.pdf
PDF
In sliding window protocol the left wall of the sender sliding winod.pdf
PDF
In mice, the black allele (B) is dominant to the recessive white all.pdf
PDF
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
PDF
Let R be an integral domain. Prove 1R and -1R are the only units of .pdf
[Quantum Mechanics] In my class we are talking about the quantum har.pdf
Write a function which return a list of all of the n element subset .pdf
what is tax preferenceSolutionTax preferences are measures of .pdf
Which of the following is true regarding homologous structuresA. .pdf
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdf
Which of the following is NOT a complication in development of an HIV.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdf
Which of the following groups is responsible for the actual developm.pdf
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdf
what does it takes to be a living organ What does it take to be a l.pdf
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
This one is for you - assume that this pedigree shows the inheritance.pdf
There are 7 people in the elevator in a 10-story building. They are .pdf
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
Question 1 A ____________ is an intelligent device that controls the.pdf
I finished most of the program, but having trouble with some key fea.pdf
In sliding window protocol the left wall of the sender sliding winod.pdf
In mice, the black allele (B) is dominant to the recessive white all.pdf
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
Let R be an integral domain. Prove 1R and -1R are the only units of .pdf
Ad

Recently uploaded (20)

PDF
African Communication Research: A review
PDF
M.Tech in Aerospace Engineering | BIT Mesra
PPTX
2025 High Blood Pressure Guideline Slide Set.pptx
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PPTX
CAPACITY BUILDING PROGRAMME IN ADOLESCENT EDUCATION
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PDF
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
PDF
Laparoscopic Colorectal Surgery at WLH Hospital
PDF
Journal of Dental Science - UDMY (2022).pdf
PPTX
UNIT_2-__LIPIDS[1].pptx.................
PPT
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
PDF
THE CHILD AND ADOLESCENT LEARNERS & LEARNING PRINCIPLES
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
PDF
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
PPTX
Thinking Routines and Learning Engagements.pptx
PPTX
Macbeth play - analysis .pptx english lit
PDF
The TKT Course. Modules 1, 2, 3.for self study
PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PPTX
Reproductive system-Human anatomy and physiology
African Communication Research: A review
M.Tech in Aerospace Engineering | BIT Mesra
2025 High Blood Pressure Guideline Slide Set.pptx
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
CAPACITY BUILDING PROGRAMME IN ADOLESCENT EDUCATION
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
Laparoscopic Colorectal Surgery at WLH Hospital
Journal of Dental Science - UDMY (2022).pdf
UNIT_2-__LIPIDS[1].pptx.................
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
THE CHILD AND ADOLESCENT LEARNERS & LEARNING PRINCIPLES
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
Thinking Routines and Learning Engagements.pptx
Macbeth play - analysis .pptx english lit
The TKT Course. Modules 1, 2, 3.for self study
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
Reproductive system-Human anatomy and physiology

A deque (pronounced deck) is an ordered set of items from which item.pdf

  • 1. A deque (pronounced deck) is an ordered set of items from which items may be deleted at either end and into which items may be inserted at either end. Call the two ends left and right. This is an access-restricted structure since no insertions or deletions can happen other than at the ends. Implement a deque as a doubly-linked circular list with a header. Write InsertRight and DeleteLeft. Solution code: #include using namespace std; class Node { public: int data; Node* next; Node* prev; }; class Deque { private: Node* front; Node* rear; int count; public: Deque() { front = NULL; rear = NULL; count = 0; } bool isEmpty()
  • 2. { if(count == 0) return true; else return false; } int DeleteLeft() { if ( isEmpty() ) { cout<<"deque is empty... can't delete'"; return -1; } int ret = front->data; Node* tmp = front; if ( front->next != NULL ) { front = front->next; front->prev = NULL; } else { front = NULL; } count--; delete tmp; return ret; } void InsertRight(int element) { Node* tmp = new Node(); tmp->data = element; tmp->next = NULL; tmp->prev = NULL; if ( isEmpty() ) { front = rear = tmp; }
  • 3. else { rear->next = tmp; tmp->prev = rear; rear = tmp; } count++; } }; int main() { Deque q; if ( q.isEmpty() ) { cout << "Deque is empty" << endl; } q.InsertRight(100); q.InsertRight(200); q.InsertRight(300); Deque q1; if ( q1.isEmpty() ) { cout << "Deque is empty" << endl; } q1.InsertRight(100); q1.InsertRight(200); q1.InsertRight(300); cout << q1.DeleteLeft() << endl; cout << q1.DeleteLeft() << endl; cout << q1.DeleteLeft() << endl; }