Question: class Node: def __init__(self, value): self.value = value self.next = None def __str__(self): return Node({}).format(self.value) __repr__ = __str__ class Queue: ''' >>> x=Queue() >>> x.isEmpty()
[10 pts] In class, we discussed the abstract data type Queue. A queue is a collection of items where the addition of new items happens at one end (tail) and the removal of existing items occurs at the other end (head) (FIFO). Use the Node class (an object with a data field and a pointer to the next element) to implement the queue data structure with the following operations: .Queue0 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 dequeue0 removes the head Node from the queue. It needs no parameters and returns the . isEmptyO tests to see whether the queue is empty. It needs no parameters and returns a lenO returns the number of items in the queue. It needs no parameters and returns an of the Node and returns nothing. value of the Node removed from the queue. The queue is modified. boolean value. integer. EXAMPLE >>>x-Queue () >>>x.isEmpty) True >>>x.dequeue ) 'Queue is empty. >>> x.enqueue (1) None is fine too x.enqueue (2) >>> x.enqueue (3) >>x.enqueue (4) >>> print(x) Head:Node (1) Tail:Node (4) Queue:1 23 4 >>> x.isEmpty) False >>>ien (x) >>> x.dequeue () MacBook Ai
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
