Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(c) Consider the following script, which uses the Node ADT: import node as node this = node.create (6, None) that = node.create (5, None) other

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

(c) Consider the following script, which uses the Node ADT: import node as node this = node.create (6, None) that = node.create (5, None) other = node.create (7, None) node.set_next (that, other) node.set_next (this, that) y = node.get_next (this) x = y y = node.get_next (y) node.set_next (other, node.create(0, None)) In the space below, draw the Global Python frame, and the heap, showing the nodes created and all the variables, and all the references, as it would appear after the script is finished. 39. In this question you will demonstrate your ability to use Python lists. Write a function named contains_duplicates () which takes a single list as an argument, and returns True if there are ANY duplicate values in the list, or False otherwise. This is similar to an assignment question, but here you will use Python lists, not node-chains. Examples: contains_duplicates ([1,0,3,5,-3]) returns False. contains_duplicates ([8,6,13,8,21]) returns True. contains_duplicates ([]) returns False since empty lists contain no duplicates. To answer this question, just give the body of the function, below the doc-string. def contains_duplicates (alist): Purpose: Returns True if the given list contains any duplicate values. Pre-conditions: param alist: a Python list, possibly empty Pre-conditions: param alist: remains unchanged Return: :return: True if duplicate value (s) were found, False otherwise 40. In this question you will demonstrate your understanding of the Queue and Stack ADTs. Write a function named reverse() that reverses a given queue. More precisely, the func- tion should take one argument, a Queue, and it should reverse the order of items in that Queue. This function returns nothing; it must modify the given queue. See the given doc- string for the specification of the required function. Note: You may not violate the ADT principle by accessing the items in a queue or stack directly. Use the ADT operations. You may not use a Python list anywhere in this question. To answer this question, just give the body of the function, below the doc-string. import Stack as Stack import Queue as Queue def reverse (aqueue): Purpose: Reverse the items in the given Queue. Pre-Conditions: aqueue: a queue created by Queue.create() Post-Conditions: The queue has the same contents as before, but the order is reversed. Return: None 41. In this question you will demonstrate your understanding of the Queue and Stack ADTS. Design and implement a function called separate_even_odd (). This function accepts one argument, a Stack created by Stack.create() containing integers, and returns a tuple containing two new Stacks, the first containing all the even data values in the given Stack, appearing in the same order as in the original Stack, and the second containing all the odd values, in the same order as the original Stack. If there are no even values in the original Stack, the Stack of even values will be empty; similarly, if there are no odd values, the Stack of odd values will be empty. One additional design constraint is that the original stack MUST be in the same state it was when it was passed in. Note: You may not violate the ADT principle by accessing the items in a queue or stack directly. Use the ADT operations. You may not use a Python list anywhere in this question. (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 separate_even_odd () 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 are not required to use a Queue, but you may. You may not use a Python list anywhere in this question. import Stack as Stack import Queue as Queue 42. In this question you will demonstrate your understanding of references, and the Node ADT, by drawing node diagrams similar to those drawn in the readings and in the lectures. You may use the simplified diagrams for nodes, as we did in class. (a) Consider the following script, which uses the Node ADT: import node as node achain = node.create (4, None) achain = node.create (3, achain) In the space below, draw the Global Python frame, and the heap, showing the nodes created and all the variables, and all the references, as it would appear after the script is finished. ) (b) Consider the following script, which uses the Node ADT: import node as node anode = node.create (1, None) bnode = node.create (2, None) node.set_next (anode, bnode) In the space below, draw the Global Python frame, and the heap, showing the nodes created and all the variables, and all the references, as it would appear after the script is finished

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

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions

Question

In what activities do you participate?

Answered: 1 week ago