A double-ended queue is a list that allows the addition and removal of entries f
ID: 3531616 • Letter: A
Question
A double-ended queue is a list that allows the addition and removal of entries from either end. One end is arbitrarily called the front and the other the rear, but two ends behave identically. Specify, design, and implement a template class for a double-ended queue. Include operations to check if it is empty or full. For each end, include operations for adding and removing entries. Implement the double-ended queue as a doubly linked list. Call your class deque ( which is pronounced "deck"). By the way, the c++ standard library has a deque class.
Explanation / Answer
#include #include #include using namespace std; class node { public: int data; class node *next; class node *prev; }; class dqueue: public node { node *head,*tail; int top1,top2; public: dqueue() { top1=0; top2=0; head=NULL; tail=NULL; } void push(int x){ node *temp; int ch; if(top1+top2 >=5) { cout next=NULL; head->prev=NULL; tail=head; top1++; } else { cout ch; if(ch==1) { top1++; temp=new node; temp->data=x; temp->next=head; temp->prev=NULL; head->prev=temp; head=temp; } else { top2++; temp=new node; temp->data=x; temp->next=NULL; temp->prev=tail; tail->next=temp; tail=temp; } } } void pop() { int ch; cout ch; if(top1 + top2 prev; tail->next=NULL; } } void display() { int ch; node *temp; cout ch; if(top1+top2Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.