>>> x = [1, 0, 3, 0, 0, 5, 7] >>> y=move_number_V1(x) >>> print(x, y) [1, 0, 3, 0, 0, 5, 7] [1, 3, 5, 7, 0, 0, 0] >>> x = [1, 0, 3, 0, 0, 5, 7] >>> z=move_number_v2(x) >>> print(x, z) [1, 3, 5, 7, 0, 0, o] None >>> x = [1, 0, 3, 0, 0, 5, 7] >>> t= move_number_v3(x) >> print(x, t) [1,3,5,7,0,0,0] None

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 18SA
icon
Related questions
Question

Please help me with this question(picture one) that should look like (picture 2). Please use your own code, a picture with the commentary in the code for a better understanding. Thank you 

>>> x = [1, 0, 3, 0, 0, 5, 7]
>>> y=move_number_V1(x)
>>> print(x, y)
[1, 0, 3, 0, 0, 5, 7] [1, 3, 5, 7, 0, 0, 0]
>>> x = [1, 0, 3, 0, 0, 5, 7] >>> z=move_number_v2(x)
>>> print(x, z)
[1, 3, 5, 7, 0, 0, 0] None
>>> x = [1, 0, 3, 0, 0, 5, 7] >>> t= move_number_v3(x)
>>> print(x, t) [1,3,5,7,0,0,0] None
Transcribed Image Text:>>> x = [1, 0, 3, 0, 0, 5, 7] >>> y=move_number_V1(x) >>> print(x, y) [1, 0, 3, 0, 0, 5, 7] [1, 3, 5, 7, 0, 0, 0] >>> x = [1, 0, 3, 0, 0, 5, 7] >>> z=move_number_v2(x) >>> print(x, z) [1, 3, 5, 7, 0, 0, 0] None >>> x = [1, 0, 3, 0, 0, 5, 7] >>> t= move_number_v3(x) >>> print(x, t) [1,3,5,7,0,0,0] None
Question: Create a move_number function that takes a list of integers
as a parameter and moves all zeros to the end of the list. For example,
if the list is [1,0,3,0,0,5,7] the result should be [1,3,5,7,0,0,0]
Prepare THREE solutions
· move_number_V1 uses another tmp list to compute the new list and
returns it as a result (easy problem). The initial list is not changed.
- move_number_v2 modifies the initial list inside the function. The
function does not return anything.
- move_number_v3 moves the elements in the initial list without using
temporary lists (more difficult problem). The function returns nothing.
We can use a temporary variable to swap two items, but we can also
use the Python swap a, b = b, a
Transcribed Image Text:Question: Create a move_number function that takes a list of integers as a parameter and moves all zeros to the end of the list. For example, if the list is [1,0,3,0,0,5,7] the result should be [1,3,5,7,0,0,0] Prepare THREE solutions · move_number_V1 uses another tmp list to compute the new list and returns it as a result (easy problem). The initial list is not changed. - move_number_v2 modifies the initial list inside the function. The function does not return anything. - move_number_v3 moves the elements in the initial list without using temporary lists (more difficult problem). The function returns nothing. We can use a temporary variable to swap two items, but we can also use the Python swap a, b = b, a
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning