Question: Write the following function. remove _ letter ( queue 1 : ListQueue, letter: str ) ListQueue: remove _ letter ( ) function removes the given
Write the following function. removeletterqueue: ListQueue, letter: str ListQueue: removeletter function removes the given letter from the given ListQueue. If the letter is not in the queue, do nothing. Test case: queue: abcde letter: d This function should return abce
By the way we have to use this way 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
