Question: 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

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?

Refactor (rewrite) our queue data structure so that, instead of using adoubly-linked list, it instead uses a singly-linked list and pointer to the

revu 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): self.linked_list.add_last(x) def dequeue (self): x = self.front() self.linked_list.remove_first() return x Pseudocode queue = Queue () len(queue) iter(queue) Time Complexity O(1) O(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) x = stack. dequeue () 0(1) 0(1) Table 4.7: Queue Operations

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!