Using Python Interested Queue Faster Enqueue Performance Expense Dequeue Modify Python Imp Q37250499

using python

You are interested in a Queue with faster enqueue performance atthe expense of dequeue.

Modify the Python implementation of the Queue ADT

such that the rear of the queue is at the end of the listinstead of the beginning. Name the new

class QueueFE() for Fast Enqueue.

classQueue:2    def __init__(self):3        self.items =[]45    def isEmpty(self):6        return self.items== []78    def enqueue(self, item):9        self.items.insert(0,item)1011    def dequeue(self):12        returnself.items.pop()1314    def size(self):15        returnlen(self.items)1617q=Queue()1819q.enqueue(4)20q.enqueue(‘dog’)21q.enqueue(True)22print(q.size())


Answer


class QueueFE: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def enqueue(self, item):

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.