Question: Write the following function. remove _ letter ( queue 1 : ListQueue, letter: str ) ListQueue: remove _ letter ( ) function removes the given

Write the following function. remove_letter(queue1: ListQueue, letter: str) ListQueue: remove_letter() function removes the given letter from the given ListQueue. If the letter is not in the queue, do nothing. Test case: queue1: a,b,c,d,e, letter: d This function should return a,b,c,e.
(**By the way we have to use this way to solve the problem**:
class LinkedQueue:
def __init__(self):
#underlying data structure is a linked list
self.queue = LinkedList()
"""return the number of elements in this queue"""
def __len__(self):
return self.queue.__len__()
"""return True if empty, False otherwise"""
def is_empty(self):
return self.queue.is_empty()
"""return front element"""
def first(self):
return self.queue.first()
"""add e to the back of the queue"""
def enqueue(self, e):
self.queue.add_last(e)
"""remove and return the front element"""
def dequeue(self):
return self.queue.remove_first()
"""return a string representation of this queue"""
def __str__(self):
return self.queue.__str__()
class ListQueue:
def __init__(self):
#underlying data structure is a list
self.queue = list()
"""return the number of elements in this queue"""
def __len__(self):
return len(self.queue)
"""return True if empty, False otherwise"""
def is_empty(self):
return len(self.queue)==0
"""return front element"""
def first(self):
if self.is_empty():
return None
return self.queue[0]
"""add e to the back of the queue"""
def enqueue(self, e):
self.queue.append(e)
"""remove and return the front element"""
def dequeue(self):
if self.is_empty():
return None
return self.queue.pop(0)
"""return a string representation of this queue"""
def __str__(self):
return str(self.queue)
if __name__=='__main__':
q1= LinkedQueue()
for e in [1,2,3,4,5]:
q1.enqueue(e)
print(q1)
while not q1.is_empty():
q1.dequeue()
print(q1)
q2= ListQueue()
for e in [1,2,3,4,5]:
q2.enqueue(e)
print(q2)
while not q2.is_empty():
q2.dequeue()
print(q2)

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 Programming Questions!