SlideShare a Scribd company logo
1 of 9
Add functions push(int n, Deque &dq) and pop(Deque &dq).
Functions push(int n, Deque &dq) and pop(Deque &dq) should call functions of the Deque
class to simulate a stack's push and pop functions.
The Deque class should not be touched . I will use the original unmodified Deque class when
testing your code.
Demonstrate to convert a base 10 number to base 2. Ask the user to enter a base 10 number,
output the equivalent base 2 number. The main() function would create a Deque object and pass
it by reference when calling the new
push(int n, Deque &dq) and pop(Deque &dq) functions simulating stack operations.
keep it simple and to the instructions and code provided please! and thank you!
// C++ implementation of De-queue using circular
// array
#include<iostream>
using namespace std;
// Maximum size of array or Dequeue
#define MAX 100
// A structure to represent a Deque
class Deque
{
int arr[MAX];
int front;
int rear;
int size;
public :
Deque(int size)
{
front = -1;
rear = 0;
this->size = size;
}
// Operations on Deque:
void insertfront(int key);
void insertrear(int key);
void deletefront();
void deleterear();
bool isFull();
bool isEmpty();
int getFront();
int getRear();
};
// Checks whether Deque is full or not.
bool Deque::isFull()
{
return ((front == 0 && rear == size-1)||
front == rear+1);
}
// Checks whether Deque is empty or not.
bool Deque::isEmpty ()
{
return (front == -1);
}
// Inserts an element at front
void Deque::insertfront(int key)
{
// check whether Deque if full or not
if (isFull())
{
cout << "Overflown" << endl;
return;
}
// If queue is initially empty
if (front == -1)
{
front = 0;
rear = 0;
}
// front is at first position of queue
else if (front == 0)
front = size - 1 ;
else // decrement front end by '1'
front = front-1;
// insert current element into Deque
arr[front] = key ;
}
// function to inset element at rear end
// of Deque.
void Deque ::insertrear(int key)
{
if (isFull())
{
cout << " Overflown " << endl;
return;
}
// If queue is initially empty
if (front == -1)
{
front = 0;
rear = 0;
}
// rear is at last position of queue
else if (rear == size-1)
rear = 0;
// increment rear end by '1'
else
rear = rear+1;
// insert current element into Deque
arr[rear] = key ;
}
// Deletes element at front end of Deque
void Deque ::deletefront()
{
// check whether Deque is empty or not
if (isEmpty())
{
cout << "Queue Underflown" << endl;
return ;
}
// Deque has only one element
if (front == rear)
{
front = -1;
rear = -1;
}
else
// back to initial position
if (front == size -1)
front = 0;
else // increment front by '1' to remove current
// front value from Deque
front = front+1;
}
// Delete element at rear end of Deque
void Deque::deleterear()
{
if (isEmpty())
{
cout << " Underflown" << endl ;
return ;
}
// Deque has only one element
if (front == rear)
{
front = -1;
rear = -1;
}
else if (rear == 0)
rear = size-1;
else
rear = rear-1;
}
// Returns front element of Deque
int Deque::getFront()
{
// check whether Deque is empty or not
if (isEmpty())
{
cout << " Underflown" << endl;
return -1 ;
}
return arr[front];
}
// function return rear element of Deque
int Deque::getRear()
{
// check whether Deque is empty or not
if(isEmpty() || rear < 0)
{
cout << " Underflown" << endl;
return -1 ;
}
return arr[rear];
}
// Driver program to test above function
int main()
{
Deque dq(5);
cout << "Insert element at rear end : 5 n";
dq.insertrear(5);
cout << "insert element at rear end : 10 n";
dq.insertrear(10);
cout << "get rear element " << " "
<< dq.getRear() << endl;
dq.deleterear();
cout << "After delete rear element new rear"
<< " become " << dq.getRear() << endl;
cout << "inserting element at front end n";
dq.insertfront(15);
cout << "get front element " << " "
<< dq.getFront() << endl;
dq.deletefront();
cout << "After delete front element new "
<< "front become " << dq.getFront() << endl;
return 0;
}
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx

More Related Content

Similar to Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx

JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
ย 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfaromalcom
ย 
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdfTo complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdfezycolours78
ย 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdffcaindore
ย 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdfafgt2012
ย 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfarorastores
ย 
I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfadianantsolutions
ย 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applicationsAhsan Mansiv
ย 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdffathimafancyjeweller
ย 
Hi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfHi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfpritikulkarni20
ย 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
ย 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfsauravmanwanicp
ย 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
ย 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
ย 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
ย 
stacks and queues
stacks and queuesstacks and queues
stacks and queuesDurgaDeviCbit
ย 

Similar to Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx (20)

JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
ย 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
ย 
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdfTo complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
To complete the task, you need to fill in the missing code. Iโ€™ve inc.pdf
ย 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
ย 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
ย 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
ย 
I need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdfI need help in writing the test cases of the below methods i.pdf
I need help in writing the test cases of the below methods i.pdf
ย 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
ย 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
ย 
Polymorphism
PolymorphismPolymorphism
Polymorphism
ย 
Dequeue.ppt
Dequeue.pptDequeue.ppt
Dequeue.ppt
ย 
Hi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfHi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdf
ย 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
ย 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
ย 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
ย 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
ย 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
ย 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
ย 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
ย 
Qprgs
QprgsQprgs
Qprgs
ย 

More from WilliamZnlMarshallc

All of the following are requirements for a Tax Professional to meet t.docx
All of the following are requirements for a Tax Professional to meet t.docxAll of the following are requirements for a Tax Professional to meet t.docx
All of the following are requirements for a Tax Professional to meet t.docxWilliamZnlMarshallc
ย 
All three articles focus on CIO's (Chief Information Officer) role in.docx
All three articles focus on CIO's (Chief Information Officer) role in.docxAll three articles focus on CIO's (Chief Information Officer) role in.docx
All three articles focus on CIO's (Chief Information Officer) role in.docxWilliamZnlMarshallc
ย 
All reflexes are characterized by a reflex arc- which includes the fol.docx
All reflexes are characterized by a reflex arc- which includes the fol.docxAll reflexes are characterized by a reflex arc- which includes the fol.docx
All reflexes are characterized by a reflex arc- which includes the fol.docxWilliamZnlMarshallc
ย 
All of the following statements are correct regarding the advantages o.docx
All of the following statements are correct regarding the advantages o.docxAll of the following statements are correct regarding the advantages o.docx
All of the following statements are correct regarding the advantages o.docxWilliamZnlMarshallc
ย 
All of the following exempt organizations have annual gross receipts o.docx
All of the following exempt organizations have annual gross receipts o.docxAll of the following exempt organizations have annual gross receipts o.docx
All of the following exempt organizations have annual gross receipts o.docxWilliamZnlMarshallc
ย 
All health professionals are allowed to practise in their field of car.docx
All health professionals are allowed to practise in their field of car.docxAll health professionals are allowed to practise in their field of car.docx
All health professionals are allowed to practise in their field of car.docxWilliamZnlMarshallc
ย 
all are true of the CFPB except- A) primary mission is to protect cons.docx
all are true of the CFPB except- A) primary mission is to protect cons.docxall are true of the CFPB except- A) primary mission is to protect cons.docx
all are true of the CFPB except- A) primary mission is to protect cons.docxWilliamZnlMarshallc
ย 
Alicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docx
Alicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docxAlicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docx
Alicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docxWilliamZnlMarshallc
ย 
Alice throws a pair of dice without being seen by Bob and tells him th.docx
Alice throws a pair of dice without being seen by Bob and tells him th.docxAlice throws a pair of dice without being seen by Bob and tells him th.docx
Alice throws a pair of dice without being seen by Bob and tells him th.docxWilliamZnlMarshallc
ย 
Alfalfa Mining Company went through a capital restructuring recently w.docx
Alfalfa Mining Company went through a capital restructuring recently w.docxAlfalfa Mining Company went through a capital restructuring recently w.docx
Alfalfa Mining Company went through a capital restructuring recently w.docxWilliamZnlMarshallc
ย 
Alex- Becky- and woora are the enly inhabitants of the smali island of.docx
Alex- Becky- and woora are the enly inhabitants of the smali island of.docxAlex- Becky- and woora are the enly inhabitants of the smali island of.docx
Alex- Becky- and woora are the enly inhabitants of the smali island of.docxWilliamZnlMarshallc
ย 
Albert Einstein believed that Entangled particles could communicate wi.docx
Albert Einstein believed that Entangled particles could communicate wi.docxAlbert Einstein believed that Entangled particles could communicate wi.docx
Albert Einstein believed that Entangled particles could communicate wi.docxWilliamZnlMarshallc
ย 
aianeit 4+ itene Cindttien inet tres.docx
aianeit 4+ itene Cindttien inet tres.docxaianeit 4+ itene Cindttien inet tres.docx
aianeit 4+ itene Cindttien inet tres.docxWilliamZnlMarshallc
ย 
After watching the video segment -Justine Chitsena-- participate in th.docx
After watching the video segment -Justine Chitsena-- participate in th.docxAfter watching the video segment -Justine Chitsena-- participate in th.docx
After watching the video segment -Justine Chitsena-- participate in th.docxWilliamZnlMarshallc
ย 
Aging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docx
Aging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docxAging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docx
Aging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docxWilliamZnlMarshallc
ย 
After the Revolutionary War- the United States was in desperate need o.docx
After the Revolutionary War- the United States was in desperate need o.docxAfter the Revolutionary War- the United States was in desperate need o.docx
After the Revolutionary War- the United States was in desperate need o.docxWilliamZnlMarshallc
ย 
After reading the information presented in this module and other sourc.docx
After reading the information presented in this module and other sourc.docxAfter reading the information presented in this module and other sourc.docx
After reading the information presented in this module and other sourc.docxWilliamZnlMarshallc
ย 
After building the 5Ws table to begin to articulate your work project-.docx
After building the 5Ws table to begin to articulate your work project-.docxAfter building the 5Ws table to begin to articulate your work project-.docx
After building the 5Ws table to begin to articulate your work project-.docxWilliamZnlMarshallc
ย 
After being absorbed- water-soluble nutrients such as glucose- fructos.docx
After being absorbed- water-soluble nutrients such as glucose- fructos.docxAfter being absorbed- water-soluble nutrients such as glucose- fructos.docx
After being absorbed- water-soluble nutrients such as glucose- fructos.docxWilliamZnlMarshallc
ย 
Additional lab results indicate that the microbe is a normal intestina.docx
Additional lab results indicate that the microbe is a normal intestina.docxAdditional lab results indicate that the microbe is a normal intestina.docx
Additional lab results indicate that the microbe is a normal intestina.docxWilliamZnlMarshallc
ย 

More from WilliamZnlMarshallc (20)

All of the following are requirements for a Tax Professional to meet t.docx
All of the following are requirements for a Tax Professional to meet t.docxAll of the following are requirements for a Tax Professional to meet t.docx
All of the following are requirements for a Tax Professional to meet t.docx
ย 
All three articles focus on CIO's (Chief Information Officer) role in.docx
All three articles focus on CIO's (Chief Information Officer) role in.docxAll three articles focus on CIO's (Chief Information Officer) role in.docx
All three articles focus on CIO's (Chief Information Officer) role in.docx
ย 
All reflexes are characterized by a reflex arc- which includes the fol.docx
All reflexes are characterized by a reflex arc- which includes the fol.docxAll reflexes are characterized by a reflex arc- which includes the fol.docx
All reflexes are characterized by a reflex arc- which includes the fol.docx
ย 
All of the following statements are correct regarding the advantages o.docx
All of the following statements are correct regarding the advantages o.docxAll of the following statements are correct regarding the advantages o.docx
All of the following statements are correct regarding the advantages o.docx
ย 
All of the following exempt organizations have annual gross receipts o.docx
All of the following exempt organizations have annual gross receipts o.docxAll of the following exempt organizations have annual gross receipts o.docx
All of the following exempt organizations have annual gross receipts o.docx
ย 
All health professionals are allowed to practise in their field of car.docx
All health professionals are allowed to practise in their field of car.docxAll health professionals are allowed to practise in their field of car.docx
All health professionals are allowed to practise in their field of car.docx
ย 
all are true of the CFPB except- A) primary mission is to protect cons.docx
all are true of the CFPB except- A) primary mission is to protect cons.docxall are true of the CFPB except- A) primary mission is to protect cons.docx
all are true of the CFPB except- A) primary mission is to protect cons.docx
ย 
Alicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docx
Alicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docxAlicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docx
Alicia- Beat- Caroline- David and Emil- Sara can talk to Emil right aw.docx
ย 
Alice throws a pair of dice without being seen by Bob and tells him th.docx
Alice throws a pair of dice without being seen by Bob and tells him th.docxAlice throws a pair of dice without being seen by Bob and tells him th.docx
Alice throws a pair of dice without being seen by Bob and tells him th.docx
ย 
Alfalfa Mining Company went through a capital restructuring recently w.docx
Alfalfa Mining Company went through a capital restructuring recently w.docxAlfalfa Mining Company went through a capital restructuring recently w.docx
Alfalfa Mining Company went through a capital restructuring recently w.docx
ย 
Alex- Becky- and woora are the enly inhabitants of the smali island of.docx
Alex- Becky- and woora are the enly inhabitants of the smali island of.docxAlex- Becky- and woora are the enly inhabitants of the smali island of.docx
Alex- Becky- and woora are the enly inhabitants of the smali island of.docx
ย 
Albert Einstein believed that Entangled particles could communicate wi.docx
Albert Einstein believed that Entangled particles could communicate wi.docxAlbert Einstein believed that Entangled particles could communicate wi.docx
Albert Einstein believed that Entangled particles could communicate wi.docx
ย 
aianeit 4+ itene Cindttien inet tres.docx
aianeit 4+ itene Cindttien inet tres.docxaianeit 4+ itene Cindttien inet tres.docx
aianeit 4+ itene Cindttien inet tres.docx
ย 
After watching the video segment -Justine Chitsena-- participate in th.docx
After watching the video segment -Justine Chitsena-- participate in th.docxAfter watching the video segment -Justine Chitsena-- participate in th.docx
After watching the video segment -Justine Chitsena-- participate in th.docx
ย 
Aging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docx
Aging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docxAging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docx
Aging Receivables and Bad Debt Expense Perkinson Corporation sells pap.docx
ย 
After the Revolutionary War- the United States was in desperate need o.docx
After the Revolutionary War- the United States was in desperate need o.docxAfter the Revolutionary War- the United States was in desperate need o.docx
After the Revolutionary War- the United States was in desperate need o.docx
ย 
After reading the information presented in this module and other sourc.docx
After reading the information presented in this module and other sourc.docxAfter reading the information presented in this module and other sourc.docx
After reading the information presented in this module and other sourc.docx
ย 
After building the 5Ws table to begin to articulate your work project-.docx
After building the 5Ws table to begin to articulate your work project-.docxAfter building the 5Ws table to begin to articulate your work project-.docx
After building the 5Ws table to begin to articulate your work project-.docx
ย 
After being absorbed- water-soluble nutrients such as glucose- fructos.docx
After being absorbed- water-soluble nutrients such as glucose- fructos.docxAfter being absorbed- water-soluble nutrients such as glucose- fructos.docx
After being absorbed- water-soluble nutrients such as glucose- fructos.docx
ย 
Additional lab results indicate that the microbe is a normal intestina.docx
Additional lab results indicate that the microbe is a normal intestina.docxAdditional lab results indicate that the microbe is a normal intestina.docx
Additional lab results indicate that the microbe is a normal intestina.docx
ย 

Recently uploaded

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
ย 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
ย 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
ย 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
ย 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
ย 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
ย 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
ย 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
ย 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
ย 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
ย 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
ย 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
ย 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
ย 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
ย 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
ย 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
ย 

Recently uploaded (20)

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
ย 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
ย 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
ย 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
ย 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
ย 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
ย 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
ย 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
ย 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
ย 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
ย 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
ย 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
ย 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
ย 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
ย 
Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
Model Call Girl in Tilak Nagar Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
ย 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
ย 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
ย 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
ย 
Model Call Girl in Bikash Puri Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
Model Call Girl in Bikash Puri  Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”Model Call Girl in Bikash Puri  Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
Model Call Girl in Bikash Puri Delhi reach out to us at ๐Ÿ”9953056974๐Ÿ”
ย 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ย 

Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx

  • 1. Add functions push(int n, Deque &dq) and pop(Deque &dq). Functions push(int n, Deque &dq) and pop(Deque &dq) should call functions of the Deque class to simulate a stack's push and pop functions. The Deque class should not be touched . I will use the original unmodified Deque class when testing your code. Demonstrate to convert a base 10 number to base 2. Ask the user to enter a base 10 number, output the equivalent base 2 number. The main() function would create a Deque object and pass it by reference when calling the new push(int n, Deque &dq) and pop(Deque &dq) functions simulating stack operations. keep it simple and to the instructions and code provided please! and thank you! // C++ implementation of De-queue using circular // array #include<iostream> using namespace std; // Maximum size of array or Dequeue #define MAX 100 // A structure to represent a Deque class Deque { int arr[MAX]; int front; int rear; int size; public : Deque(int size)
  • 2. { front = -1; rear = 0; this->size = size; } // Operations on Deque: void insertfront(int key); void insertrear(int key); void deletefront(); void deleterear(); bool isFull(); bool isEmpty(); int getFront(); int getRear(); }; // Checks whether Deque is full or not. bool Deque::isFull() { return ((front == 0 && rear == size-1)|| front == rear+1); } // Checks whether Deque is empty or not. bool Deque::isEmpty ()
  • 3. { return (front == -1); } // Inserts an element at front void Deque::insertfront(int key) { // check whether Deque if full or not if (isFull()) { cout << "Overflown" << endl; return; } // If queue is initially empty if (front == -1) { front = 0; rear = 0; } // front is at first position of queue else if (front == 0) front = size - 1 ; else // decrement front end by '1' front = front-1;
  • 4. // insert current element into Deque arr[front] = key ; } // function to inset element at rear end // of Deque. void Deque ::insertrear(int key) { if (isFull()) { cout << " Overflown " << endl; return; } // If queue is initially empty if (front == -1) { front = 0; rear = 0; } // rear is at last position of queue else if (rear == size-1) rear = 0; // increment rear end by '1' else
  • 5. rear = rear+1; // insert current element into Deque arr[rear] = key ; } // Deletes element at front end of Deque void Deque ::deletefront() { // check whether Deque is empty or not if (isEmpty()) { cout << "Queue Underflown" << endl; return ; } // Deque has only one element if (front == rear) { front = -1; rear = -1; } else // back to initial position if (front == size -1) front = 0;
  • 6. else // increment front by '1' to remove current // front value from Deque front = front+1; } // Delete element at rear end of Deque void Deque::deleterear() { if (isEmpty()) { cout << " Underflown" << endl ; return ; } // Deque has only one element if (front == rear) { front = -1; rear = -1; } else if (rear == 0) rear = size-1; else rear = rear-1; }
  • 7. // Returns front element of Deque int Deque::getFront() { // check whether Deque is empty or not if (isEmpty()) { cout << " Underflown" << endl; return -1 ; } return arr[front]; } // function return rear element of Deque int Deque::getRear() { // check whether Deque is empty or not if(isEmpty() || rear < 0) { cout << " Underflown" << endl; return -1 ; } return arr[rear]; } // Driver program to test above function
  • 8. int main() { Deque dq(5); cout << "Insert element at rear end : 5 n"; dq.insertrear(5); cout << "insert element at rear end : 10 n"; dq.insertrear(10); cout << "get rear element " << " " << dq.getRear() << endl; dq.deleterear(); cout << "After delete rear element new rear" << " become " << dq.getRear() << endl; cout << "inserting element at front end n"; dq.insertfront(15); cout << "get front element " << " " << dq.getFront() << endl; dq.deletefront(); cout << "After delete front element new " << "front become " << dq.getFront() << endl; return 0; }