You need to implement a class for Dequeue i.e. for double ended queue. In this queue, elements can be inserted and deleted from both the ends.   You don't need to double the capacity.   You need to implement the following functions -   1. constructor   You need to create the appropriate constructor. Size for the queue passed is 10.   2. insertFront -   This function takes an element as input and insert the element at the front of queue. Insert the element only if queue is not full. And if queue is full, print -1 and return.   3. insertRear -   This function takes an element as input and insert the element at the end of queue. Insert the element only if queue is not full. And if queue is full, print -1 and return.   4. deleteFront -   This function removes an element from the front of queue. Print -1 if queue is empty.   5. deleteRear -   This function removes an element from the end of queue. Print -1 if queue is empty.   6. getFront -   Returns the element which is at front of the queue. Return -1 if queue is empty.   7. getRear -   Returns the element which is at end of the queue. Return -1 if queue is empty.   Input Format:   For C++ and Java, input is already managed for you. You just have to implement given functions.       For Python:   The choice codes and corresponding input for each choice are given in a new line. The input is terminated by integer -1. The following table elaborately describes the function, their choice codes and their corresponding input -   Alt Text       Output Format:   For C++ and Java, output is already managed for you. You just have to implement given functions.       For Python:   The output format for each function has been mentioned in the problem description itself.   Sample Input 1:   5 1 49 1 64 2 99 5 6 -1   Sample Output 1:   -1   64   99   Explanation:   The first choice code corresponds to getFront. Since the queue is empty, hence the output is -1.   The following input adds 49 at the top and the resultant queue becomes: 49.   The following input adds 64 at the top and the resultant queue becomes: 64 -> 49   The following input add 99 at the end and the resultant queue becomes: 64 -> 49 -> 99   The following input corresponds to getFront. Hence the output is 64.   The following input corresponds to getRear. Hence the output is 99..

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
icon
Concept explainers
Question
You need to implement a class for Dequeue i.e. for double ended queue. In this queue, elements can be inserted and deleted from both the ends.
  You don't need to double the capacity.
  You need to implement the following functions -
  1. constructor
  You need to create the appropriate constructor. Size for the queue passed is 10.
  2. insertFront -
  This function takes an element as input and insert the element at the front of queue. Insert the element only if queue is not full. And if queue is full, print -1 and return.
  3. insertRear -
  This function takes an element as input and insert the element at the end of queue. Insert the element only if queue is not full. And if queue is full, print -1 and return.
  4. deleteFront -
  This function removes an element from the front of queue. Print -1 if queue is empty.
  5. deleteRear -
  This function removes an element from the end of queue. Print -1 if queue is empty.
  6. getFront -
  Returns the element which is at front of the queue. Return -1 if queue is empty.
  7. getRear -
  Returns the element which is at end of the queue. Return -1 if queue is empty.
  Input Format:
  For C++ and Java, input is already managed for you. You just have to implement given functions.
   
  For Python:
  The choice codes and corresponding input for each choice are given in a new line. The input is terminated by integer -1. The following table elaborately describes the function, their choice codes and their corresponding input -
  Alt Text
   
  Output Format:
  For C++ and Java, output is already managed for you. You just have to implement given functions.
   
  For Python:
  The output format for each function has been mentioned in the problem description itself.
  Sample Input 1:
  5 1 49 1 64 2 99 5 6 -1
  Sample Output 1:
  -1
  64
  99
  Explanation:
  The first choice code corresponds to getFront. Since the queue is empty, hence the output is -1.
  The following input adds 49 at the top and the resultant queue becomes: 49.
  The following input adds 64 at the top and the resultant queue becomes: 64 -> 49
  The following input add 99 at the end and the resultant queue becomes: 64 -> 49 -> 99
  The following input corresponds to getFront. Hence the output is 64.
 

The following input corresponds to getRear. Hence the output is 99..

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning