Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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_next_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 letter of the string and adding it and the letter following it in the alphabet to the end of the string. You can assume that the string is not empty and all characters are lower case letters, e.g., the next letter after ' a ' is 'b'. If we get the letter ' z ', then the next letter should be 'a'. Examples: - put_next_at_end(0, "azb") is "azb" - put_next_at_end(1, "azb") is "zbab" ('a' has been removed from the beginning and added at the end followed by 'b' (the next letter after 'a' in the alphabet) - put_next_at_end(2, "azb") is "babza" (the first iteration yields "zbab", the second iteration removes 'z' and adds it and 'a' (the letter following 'z') at the end) - put_next_at_end(3, "azb") is "abzabc" . 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions