Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

31. In this question you will demonstrate your understanding of the Queue and Stack ADTS. Do not violate the ADT Principle in this question. We

image text in transcribedimage text in transcribedimage text in transcribed

31. In this question you will demonstrate your understanding of the Queue and Stack ADTS. Do not violate the ADT Principle in this question. We want to design a function called duplicate. This function is to have one parameter, a Stack created by Stack.create(), and it must return a new Stack. The function's purpose is to duplicate the given stack, so by the end of the function, there will be two distinct queues containing the same elements in the same order. The new stack has to be distinct, but still contain the same elements as the given stack. (a) Complete the documentation of the interface of the function by adding information to the template below. Purpose: Pre-conditions: Post-conditions: Return: (b) Define the function duplicate () in the space below. You do not need to give a doc- string here, because you did that above. We've imported the ADTs for you. You may not use a Python list anywhere in this question. import Stack as Stack import Queue as Queue - Write a function named find_missing that checks if a given list contains all the val- ues 1,2,...,n, where n is the length of the list. For example, find_missing ( [3,1,2]) returns [], and find_missing ([1,5,0]) returns [2,3]. This is related to functions you wrote in Assignments 1 and 2. You may solve this any way you like; the only requirement is that it is consistent with the interface given below as a doc-string. To answer this question, just give the body of the function, below the doc-string. def find_missing (alist): Purpose: Return a list of numbers 1 ... N that do not appear in alist Here, N is the length of alist. Pre-conditions: alist: a list of integers Post-conditions: None Return: A list of the numbers in l... N that do not appear in alist. In this question you will demonstrate your understanding of the Queue and Stack ADTS. Do not violate the ADT Principle in this question. We want to design a function called drop. This function is to take two arguments: one is a Queue created by Stack.create(), and the other is a number. The purpose of the function drop() is to remove all the values in the queue less than the given number, assuming that the queue contains numbers in increasing order. For example, suppose that the function is given a queue containing the numbers 1 2 3 4 and the number 3; the function drop () will remove all the numbers strictly less than 3, leaving the values 3 4 in the queue. (a) Complete the documentation of the interface of the function by adding information to the template below. Purpose: Pre-conditions: Post-conditions: Return: (b) Define the function drop() in the space below. You do not need to give a doc-string here, because you did that above. We've imported the ADTs for you. You may not use a Python list anywhere in this question. import Stack as Stack import Queue as Queue

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

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions