
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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](https://content.bartleby.com/qna-images/question/66301e59-a86d-47c0-9dd8-21e24614422a/a5a8ebc3-cf7d-474b-ac7b-ae35f69c3e3e/vuycrvh_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 2 images

Knowledge Booster
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
- Simple JAVA queue code implementation please help for any part, please be clear, thank you Given an interface for Queue- Without using the java collections interface (ie do not import java.util.List,LinkedList, Stack, Queue...)- Create an implementation of Queue interface provided- For the implementation create a tester to verify the implementation of thatdata structure performs as expected Wait in line – Queue (fifo)- Implement the provided Queue interface ( fill out the implementation shell)- Put your implementation through its paces by exercising each of the methods ina test harness- Add to your ‘BusClient’ the following functionality using your Queue-o Create (enqueue) 6 riders by name§ Iterate over the queue, print all riderso Peek at the queue / print the resulto Remove (dequeue) the head of the queue§ Iterate over the queue, print all riderso Add two more riders to the queueo Peek at the queue & print the resulto Remove the head & print the result§ Iterate over the…arrow_forwardDraw a UML class diagram for the following code: class Node: def __init__(self, value): self.value = value self.next = None class Stack: def __init__(self): self.top = None def isEmpty(self): return self.top is None def push(self, item): new_node = Node(item) new_node.next = self.top self.top = new_node def pop(self): if self.isEmpty(): raise Exception("Stack is empty") popped_item = self.top.value self.top = self.top.next return popped_item def popAll(self): items = [] while not self.isEmpty(): items.append(self.pop()) return items[::-1] def peek(self): if self.isEmpty(): raise Exception("Stack is empty") return self.top.value # Verificationstack = Stack()print("Is stack empty?", stack.isEmpty()) stack.push(10)stack.push(20)stack.push(30)print("Top item:", stack.peek()) print("Popped item:", stack.pop())print("Popped…arrow_forwardGiven the following specification of a front operation for queue:ItemType Front Function: Returns a copy of the front item on the queue. Precondition: Queue is not empty. Postcondition: Queue is not changed. 1. Write this operation as client code, using operations from the QueType class. (Remember,the client code has no access to the private variables of the class). 2. Write this function as a new member function of the QueType class. help me with complete codearrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education