Code it · Change it
Make bubble sort put the largest first
This bubble sort works: it sorts arr smallest first. Change it so it sorts **largest first** instead.
Before you edit, predict: how many characters need to change? Then run it and watch the big values sink to the front.
def bubble_sort(arr):
n = len(arr)
for i in range(n - 1):
for j in range(n - 1 - i):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]