Question: in python: Refactor (rewrite) our queue data structure so that, instead of using a doubly-linked list, it instead uses a singly-linked list and pointer to
Refactor (rewrite) our queue data structure so that, instead of using a doubly-linked list, it instead uses a singly-linked list and pointer to the last list node. The time complexity of all operations in your list should match those in Table 4.7. Which variant do you prefer, and why class Queue: def __init__(self): self.linked_list - Linkedlist() def __len__(self): return len(self.linked_list) def __iter..(self): return iter(self.linked_list) def front (self): return self.linked list first() def enqueue (self, x): selt.linked list. add_last(x) def degueue (self): x = self.front () self.linked_list.remove_first() return x Pseudocode queue - Queue () len (queue) iter (queue) Time Complexity 0(1) 0(1) 0(1) Queue Operation Create an empty queue Get the length of a queue Get an iterator for the elements in front- to-back order Get the element at the front of a non- empty queue Add element to the back Remove and return the element at the front x - queue front() 0(1) queue enqueue(x) atack dequeue 0(1) O(1) x Table 17Queue Operations
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
