Answer:
a)
int: [10, 20, 10, 5]
out: [0, 10, 20, 10]
b)
int: [8, 2, 9, 7, -1, 55]
out: [0, 0, 8, 9, -1, 55]
c)
int: [0, 16, 9, 1, 64, 25, 25, 14]
out: [0, 0, 0, 0, 16, 9, 64, 25]
Step-by-step explanation:
What the code is doing is changing the list if and only if the item number i, where i is an odd position on the list, is greater than the item number i-1. If the condition mentioned is satisfied, the element number i is removed, and a zero is added to the beginning of the list; this is why the dimension of the input is equal to the output (for every element removed a zero is added).
Note:
- The first item of a list is the item 0
- .add method can receive two parameters the first indicating the position where the element will be added and the second the element to be added.
- .get method allows you to select any element on the list by its index.
- .size method gives you the size of the list
- In the for loop i += 2 indicates an increment of two, since we start with i = 1 we are going to iterate through odd numbers i = 1,3,5,7...