Question: Define a class Queue which implements the abstract data type queue. As part of your definition of Queue define the following methods: init__(self) which creates

 Define a class Queue which implements the abstract data type queue.

Define a class Queue which implements the abstract data type queue. As part of your definition of Queue define the following methods: init__(self) which creates an empty queue enqueue(self, x) which adds x to the end of the queue. dequeue (self) which removes and returns the first (oldest element in the queue. len_(self) which return the total number of elements currently in the queue You are free to define and use suitablo instance variables to store the items in the queue. If the method dequeue is called for an empty queue, it should execute the statement raise IndexError In 1: class Queue: def _init__(self): # YOUR CODE HERE raise Not ImplementedError() det enqueue (self,x): # YOUR CODE HERE raise Not ImplementedError() def dequeue(self): #YOUR CODE HERE raise Not implementedError() def _len_(self): # YOUR CODE HERE raise Not ImplementedError() In 1: 0 - Queue() 0.enqueue(1) : 0.enqueue(2) : 0.enqueue (3) assert 0.dequeue() 1 assert 0.dequeuel) - 2 assert 0.dequeuel) - 3 In 1: 0 - Queue) : 0.enqueue(e) : 0.dequeue() try: 0.dequeue() except IndexError: pass else! raise AssertionError

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!