Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed
image text in transcribed
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

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

How is the education level required for a position established?

Answered: 1 week ago