Question: 1) Refactor (rewrite) our queue data structure so that, instead of using a doubly-linked list, it instead uses two stacks. The time complexity of all
1) Refactor (rewrite) our queue data structure so that, instead of using a doubly-linked list, it instead uses two stacks. The time complexity of all operations in your list should match those in Table 1 (although some of the time bounds for your structure may be amortized). Which variant do you prefer, and why?
Queue data

Table 1

class Queue: def init__(self): def __len(self): def __iter_(self): def front (self): def enqueue (self, x): def dequeue(self): self, linked-list LinkedList() return len (self.linked list) return iter(self.linked list) return self.linked list.first() self.linked_list.add last(x) x self. front () self.linked list.remove first() return x
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
