Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python 3 defining a Class - Lots of screenshots uploaded for reference/background info Q2.1: Implement the Queue You will need the following instance attributes: front
Python 3 defining a Class - Lots of screenshots uploaded for reference/background info
Q2.1: Implement the Queue You will need the following instance attributes: front - index of the front of the queue rear - index of the first empty slot (or index of the last element, it is up to you) num_elems integer that tracks the number of elements present in the queue capacity - capacity of the queue, initially 3, initialize your array with elements set to None data - an array of length capacity (represents your queue) To implement the behavior of the ADT you need to provide implementations for the following methods . dequeue - removes and returns the front element. Notice the asserts in the doctests! Do create an assert statement in this method. enqueue - adds element, doubling the capacity if is full .is_ful1 - checks whether a queue is full. Returns True if full, False otherwise. is_empty - checks whether a queue is empty. Returns True if empty, False otherwise. print_queue-prints queue. o Format: Assume that elements 4, 5, 6, 7, 8 were added to the queue q. Then q. print-queue() will print: [ I 4 I 5 I 6 I 7 I 8 I NOTE: There are spaces in between the | and the numbers in q.print_queue ). If you ignore these spaces, you will lose some points o If a queue is empty, print: [ ] Define class Queue that implements the ADT (Abstract Data Type) Queue using a circular array. . You must use a np.array for this question: o Somewhere in your constructor you must have a line that looks like self.data - o If you use a Python list, then your solution will get a 0 You must observe the FIFO convention. When implementing a queue, we have to worry about running time for its basic operations: dequeue and enqueue. Both of them must run in Theta(1) Unfortunately, a regular array does not give you desired complexity. Let me explain why: We will assume that front (index) points to the front of a queue, and rear (index) points to the end of a queue, to the next available location. Front always stays at 0, and we move rear when we add elements. AssertionError: attempt to dequeue from an empty queue >b.enqueue (1) >b.enqueue (max) >>b.print_queue() [ 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started