Question: ( In Python ) Given an integer k and a queue of items. Write a program to reverse the order of the first k elements
In PythonGiven an integer k and a queue of items. Write a program to reverse the order of the first k elements of the queue. The other elements will be in the same relative order.
The following standard operations are allowed on the queue:
enqueueitem:insert an item to the rear of queue
dequeue: remove an item from the front of queue, and return the value
size: return the size of queue
isempty: return true if the queue has no elements
# Example
Input: Q
k
Output: Q
Explanation: The first elements of Q are reversed.
# Example
Input: Q
k
Output: Q
Explanation: The first elements of Q are reversed. The rest elements remains the same order
Task pts: Create and define class of Queue and Stack Create both Queue.py and Stack.py
Task pts: Import both Queue and Stack prpperly into main.py
Taskpts: Modify the following code and insert the missing parts to fullfill the program
Solution:
step Create and implement class Queue in a seperate Queue.py file under the main.py
step You will also need to create stack objects when completing the task, create or upload the Stack.py file as well
step define a function named reversekthitemlist, k in main.py which requires two input parameters, the itemlist will hold a sequence of nums or items, k is an integer which determines how many elements in the list to be reversed, use the following test cases to verify your program
printreversekth
printreversekthOne "Two", "Three", "Four"
printreversekth
printreversekth
# Sample output of above print statements:
Four,Three,Two,One
Error:The second input k is too big, should be less than or equal with the size of your Queue
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
