def bubble_up(L: list, start: int, end: int) -> None: \"\"\"Bubble up through L[
ID: 3734361 • Letter: D
Question
def bubble_up(L: list, start: int, end: int) -> None:
"""Bubble up through L[start:end], swapping items that are out of order.
>>> L = [4, 3, 2, 1, 0]
>>> bubble_up(L, 0, 3)
>>> L
[3, 2, 1, 4, 0]
>>> L = [4, 3, 2, 1, 0]
>>> bubble_up(L, 2, 4)
>>> L
[4, 3, 1, 0, 2]
"""
for i in range(start, end):
if L[i] > L[i + 1]:
L[i], L[i + 1] = L[i + 1], L[i]
def bubble_down(L: list, start: int, end: int) -> None:
"""Bubble down through L from indexes end through start, swapping items that are out of place.
>>> L = [4, 3, 2, 1, 0]
>>> bubble_down(L, 1, 3)
>>> L [4, 1, 3, 2, 0] """
Explanation / Answer
def bubble_down(L, start, end): for i in range(end-1, start-1, -1): if L[i] > L[i + 1]: L[i], L[i + 1] = L[i + 1], L[i] print(L)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.