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
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PPTX
Education and Perspectives of Education.pptx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PPTX
Computer Architecture Input Output Memory.pptx
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
HVAC Specification 2024 according to central public works department
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
What if we spent less time fighting change, and more time building what’s rig...
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
My India Quiz Book_20210205121199924.pdf
Education and Perspectives of Education.pptx
B.Sc. DS Unit 2 Software Engineering.pptx
Computer Architecture Input Output Memory.pptx
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Environmental Education MCQ BD2EE - Share Source.pdf
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
HVAC Specification 2024 according to central public works department
Paper A Mock Exam 9_ Attempt review.pdf.

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; }