Question: EXISTING CODE class Queue: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def enqueue(self, item): self.items.insert(0,item) def dequeue(self): if self.is_empty(): raise IndexError('ERROR:
![EXISTING CODE class Queue: def __init__(self): self.items = [] def is_empty(self):](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66dbe10f6c476_03066dbe10ee6e67.jpg)
EXISTING CODE
class Queue: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def enqueue(self, item): self.items.insert(0,item) def dequeue(self): if self.is_empty(): raise IndexError('ERROR: The queue is empty!') return self.items.pop() def size(self): return len(self.items) def peek(self): if self.is_empty(): raise IndexError('ERROR: The queue is empty!') return self.items[len(self.items)-1] def __str__(self): return '-> |' + str(self.items)[1:-1] + '| ->' def clear(self): self.items = []
By using a queue, write a function named put_double_at_end ( n, string) which takes an integer and a string as parameters and returns a string which has been created by n times taking the first character of the string and adding it twice to the end of the string. Examples: - put_double_at_end (0, "abc" ) is "abc" - put_double_at_end(1, "abc") is "bcaa" ('a' has been removed from the beginning and added twice at the end) - put_double_at_end(2, "abc") is "caabb" (the first iteration yields "bcaa", the second iteration removes 'b" and adds it twice at the end) - put_double_at_end (3, "abc" ) is "aabbcc". IMPORTANT: You must use a queue to solve the question. You cannot use slicing of strings. The Queue ADT with the methods Queue(), enqueue(), dequeue(), and is_empty() is defined. Click here to download the source code for the Queue class. For example: Answer: (penalty regime: 0,0,5,10,15,20,25,30,35,40,45,50% )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
