from random import randint
lst = [randint(-50, 50) for _ in range(15)]
print("before bubble sort:", lst)
for i in range(15):
for j in range(15 - i - 1):
if lst[j] > lst[j + 1]:
lst[j], lst[j + 1] = lst[j + 1], lst[j]
print('after bubble sort:', lst)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
from random import randint
lst = [randint(-50, 50) for _ in range(15)]
print("before bubble sort:", lst)
for i in range(15):
for j in range(15 - i - 1):
if lst[j] > lst[j + 1]:
lst[j], lst[j + 1] = lst[j + 1], lst[j]
print('after bubble sort:', lst)