Design a class called Queue that implements the queue data structure. A queue is a data structure where elements are added at the end and removed from the front (FIFO structure). Here is the UML diagram for the queue as well as the contract description : Queue -que :double[] -front :int -back: int -numElem :int +Queue() +Queue(capacity: int) +empty():boolean +full():boolean +front(): double +pop_front(): void +push_back(value:double):void +capacity(): int; An array to store doubles in the queue Tells us where the front of the queue is Tells us where the back (tail) of queue is Number of elements in the queue Constructs an empty Queue of default capacity 16 Constructs an empty Queue with specified capacity Returns true if queue is empty Returns true if queue is full (not needed here) Returns element at front of queue Removes element from front of queue Adds element to end (tail) of queue Returns capacity (ie length of array que) Some things to consider when you are implementing this class : 1. both constructors are responsible for creating the array que. The second constructor must make sure that capacity is >=0. If it is not then it will create the array que with default size 16 ( just like the no-arg constructor). This is a perfect place to use the this pointer. Also, remember to use a named constant for the value 16. 2. Use the value of numElem to determine if the queue is empty. 3. front(), like top() in the stack class, does not remove the element from the queue. 4. The queue should never fill up. If you try to add another double to the queue and there is no room in que for that element, then allocate a new array with twice the capacity of que, copy all elements in que to the new array and make the new array your new que. The garbage collector will

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
Design a class called Queue that implements the queue data structure. A queue is
a data structure where elements are added at the end and removed from the
front (FIFO structure). Here is the UML diagram for the queue as well as the
contract description :
Queue
-que :double[]
-front :int
-back: int
-numElem :int
+Queue()
+Queue(capacity: int)
+empty():boolean
+full():boolean
+front(): double
+pop_front(): void
+push_back(value :double):void
+capacity(): int;
An array to store doubles in the queue
Tells us where the front of the queue is
Tells us where the back (tail) of queue is
Number of elements in the queue
Constructs an empty Queue of default capacity 16
Constructs an empty Queue with specified capacity
Returns true if queue is empty
Returns true if queue is full ( not needed here)
Returns element at front of queue
Removes element from front of queue
Adds element to end (tail) of queue
Returns capacity (ie length of array que)
Some things to consider when you are implementing this class :
1. both constructors are responsible for creating the array que. The second
constructor must make sure that capacity is >=0. If it is not then it will
create the array que with default size 16 ( just like the no-arg constructor).
This is a perfect place to use the this pointer. Also, remember to use a
named constant for the value 16.
2. Use the value of numElem to determine if the queue is empty.
3. front(), like top() in the stack class, does not remove the element from the
queue.
4. The queue should never fill up. If you try to add another double to the
queue and there is no room in que for that element, then allocate a new
array with twice the capacity of que, copy all elements in que to the new
array and make the new array your new que. The garbage collector will
Transcribed Image Text:Design a class called Queue that implements the queue data structure. A queue is a data structure where elements are added at the end and removed from the front (FIFO structure). Here is the UML diagram for the queue as well as the contract description : Queue -que :double[] -front :int -back: int -numElem :int +Queue() +Queue(capacity: int) +empty():boolean +full():boolean +front(): double +pop_front(): void +push_back(value :double):void +capacity(): int; An array to store doubles in the queue Tells us where the front of the queue is Tells us where the back (tail) of queue is Number of elements in the queue Constructs an empty Queue of default capacity 16 Constructs an empty Queue with specified capacity Returns true if queue is empty Returns true if queue is full ( not needed here) Returns element at front of queue Removes element from front of queue Adds element to end (tail) of queue Returns capacity (ie length of array que) Some things to consider when you are implementing this class : 1. both constructors are responsible for creating the array que. The second constructor must make sure that capacity is >=0. If it is not then it will create the array que with default size 16 ( just like the no-arg constructor). This is a perfect place to use the this pointer. Also, remember to use a named constant for the value 16. 2. Use the value of numElem to determine if the queue is empty. 3. front(), like top() in the stack class, does not remove the element from the queue. 4. The queue should never fill up. If you try to add another double to the queue and there is no room in que for that element, then allocate a new array with twice the capacity of que, copy all elements in que to the new array and make the new array your new que. The garbage collector will
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Depth First Search
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education