Question: In PYTHON! Implement the queue data structure with the following operations: ? Queue() creates a new queue that is empty. It needs no parameters and
In PYTHON!
Implement the queue data structure with the following operations: ?
Queue() creates a new queue that is empty. It needs no parameters and returns nothing
enqueue(item) adds a new Node with value=item to the tail of the queue. It needs the value of the Node and returns nothing. [3 pts] ?
dequeue() removes the head Node from the queue. It needs no parameters and returns the value of the Node removed from the queue. The queue is modified. [3 pts] ?
isEmpty() tests to see whether the queue is empty. It needs no parameters and returns a boolean value. [2 pts] ?
size() returns the number of items in the queue. It needs no parameters and returns an integer. [2 pts]
Code Template:
class Node:
def __init__(self, value):
self.value = value
self.next = None
def getValue(self):
return self.value
def getNext(self):
return self.next
def setValue(self,new_value):
self.value = new_value
def setNext(self,new_next):
self.next = new_next
def __str__(self):
return ("{}".format(self.value))
__repr__ = __str__
class Queue:
#Do NOT modify the initializer
def __init__(self):
self.count = 0
self.head = None
self.tail = None
def isEmpty(self):
#write your code here
def size(self):
#write your code here
def enqueue(self, item):
#write your code here
def dequeue (self):
#write your code here
def printQueue(self):
temp = self.head
while (temp):
print(temp.value, end=' ')
temp = temp.next
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
