for i in range(left, right): if values[i] > values[i + 1]: values[i], values[i + 1] = values[i + 1], values[i]
Hi! I am doing this function but it isn't working. how can I fix it
def bubble_down(values: list, left: int, right: int) -> None:
"""Bubble down through values[left: right+1], swapping items that are out
of order. Note that use of this slicing notation means that items
values[left], values[left + 1], values[left + 2], ..., values[right] could
be modified.
Precondition: left and right are valid indexes in values.
>>> list_example_1 = [4, 3, 2, 1, 0]
>>> bubble_down(list_example_1, 1, 3)
>>> list_example_1
[4, 1, 3, 2, 0]
>>> list_example_2 = [4, 3, 2, 1, 0]
>>> bubble_down(list_example_2, 0, 4)
>>> list_example_2
[0, 4, 3, 2, 1]
"""
for i in range(left, right):
if values[i] > values[i + 1]:
values[i], values[i + 1] = values[i + 1], values[i]
Step by step
Solved in 3 steps