Question: Define a function named stackToQueue. This function expects a stack as an * argument. The function builds and returns an instance of LinkedQueue that contains

Define a function named stackToQueue. This function expects a stack as an * argument. The function builds and returns an instance of LinkedQueue that contains the items in the stack. The function assumes that the stack has the interface described in Chapter 7, "Stacks." The function's postconditions are that the stack is left in the same state as it was before the function was called, and that the queue's front item is the one at the top of the stack.
 Define a function named stackToQueue. This function expects a stack as
an * argument. The function builds and returns an instance of LinkedQueue

2. Define a function named stackToqueue. This function expects a stack as an +++argument. The function builds and returns an instance of LinkedQueue that contains the items in the stack. The function assumes that the stack has the interface described in Chapter 7, "Stacks." The function's postconditions are that the stack is left in the same state as it was before the function was called, and that the queue's front item is the one at the top of the stack. File Name: Description: Author: Date: \#Reuse your Queue Implementation from Q2. class Queue: TODO: Remove the "pass" statements and implement each method Add any methods if necesssary DON'T use any builtin queue class to store your items def \( \frac{\text { init___(self): \# Constructor function }}{\text { pass }} \) def isempty(self): \# Returns True if the queue is empty or False otherwise pass def len(self): \# Returns the number of items in the queue pass def peek(self): \# Returns the item at the front of the queue pass def add(self, item): # Adds item to the rear of the queue pass. def pop(self): \# Removes and returns the item at the front of the queue pass def remove(self, index): \# Removes and returns the item at index of the queue pass def stackToQueue (stack): "'input stack wilL be in the form of a list. Implement your Queue. We will pop() the elements and compare with the LIFo order of the stack \#TODO (optional): Your testing code here queue = Queue ( ) return queue if name=="mainstack=[1,2,3]res=stackToQueue(stack)print(res.pop())#theautograderwilluseyourQueuespop()function,append to a list and compare with initial stack. Correct output of res would be a Linkedqueue in the order 3,2,1

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