Question: def duplicate ( queue 1 : LinkedQueue ) - > LinkedQueue : duplicate ( ) function removes the duplicates from the given LinkedQueue then return
def duplicatequeue: LinkedQueue LinkedQueue : duplicate function removes the duplicates from the given LinkedQueue then return the resulting queue. Test case: queue:
This function should return
Btw we have to use this say to solve the problem:
class LinkedQueue:
def initself:
#underlying data structure is a linked list
self.queue LinkedList
return the number of elements in this queue"""
def lenself:
return self.queue.len
return True if empty, False otherwise"""
def isemptyself:
return self.queue.isempty
return front element"""
def firstself:
return self.queue.first
add e to the back of the queue"""
def enqueueself e:
self.queue.addlaste
remove and return the front element"""
def dequeueself:
return self.queue.removefirst
return a string representation of this queue"""
def strself:
return self.queue.str
class ListQueue:
def initself:
#underlying data structure is a list
self.queue list
return the number of elements in this queue"""
def lenself:
return lenselfqueue
return True if empty, False otherwise"""
def isemptyself:
return lenselfqueue
return front element"""
def firstself:
if self.isempty:
return None
return self.queue
add e to the back of the queue"""
def enqueueself e:
self.queue.appende
remove and return the front element"""
def dequeueself:
if self.isempty:
return None
return self.queue.pop
return a string representation of this queue"""
def strself:
return strselfqueue
if namemain:
q LinkedQueue
for e in :
qenqueuee
printq
while not qisempty:
qdequeue
printq
q ListQueue
for e in :
qenqueuee
printq
while not qisempty:
qdequeue
printq
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
