Question: Write a function called rearrange that takes a list of integer values as a parameter and that moves to the end of the list
Write a function called rearrange that takes a list of integer values as a parameter and that moves to the end of the list all values originally appearing in odd index positions in the list, preserving the relative order of these values. For example, suppose that a variable called list stores the following sequence of values: [0, 1, 2, 3, 4, 5, 6, 7, 81 and we make the following call: rearrange (list) Afterwards the list should store the following sequence of values: [0, 2, 4, 6, 8, 1, 3, 5, 71 Notice that the values originally stored in odd indexes have been moved to the end of the list (1, 3, 5, and 7). This example involved sequential integers to make it easier to see exactly which values are moved, but this won't always be the case. For example, if the list had instead stored: [14, 8, 6, 3, 1, 4, 2, 19, 42, 911 1 I values to be moved then it would store the following values after the function executes: [14, 6, 1, 2, 42, 8, 3, 4, 19, 91 Notice that what matters is whether values are in odd index positions, not whether they are odd numbers (the values 8, 3, 4, 19, and 9 in the example). You may not construct any extra data structures to solve this problem. You must solve it by manipulating the list you are passed as a parameter.
Step by Step Solution
3.29 Rating (152 Votes )
There are 3 Steps involved in it
The detailed ... View full answer
Get step-by-step solutions from verified subject matter experts
