I am trying to apply a bubble sort algorithm. My aim is to change only certain numbers in order. How may I implement it?
There is my code below.
def bubble_sort(numbers):
for i in range(len(numbers) – 1):
for j in range(len(numbers) – i – 1):
if numbers[j] > numbers[j + 1]:
temp = numbers[j]
numbers[j] = numbers[j + 1]
numbers[j + 1] = temp
print(numbers)
transactions = [100, 200, 90, 70, 120]
Actual output: [70, 90, 100, 120, 200]
Desired output: [90, 70, 100, 120, 200]
Yrysbek Raiapov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.