Files
labs/labPython/lab7/sort_methods.py
2026-04-18 14:42:00 +05:00

33 lines
1011 B
Python
Executable File

def printSortedList(list: list, sortedCount: int) -> None:
text = ""
for index in range(len(list)):
if index != sortedCount:
text += f"{list[index]}, "
else:
if sortedCount != 0:
text += f"{list[index]}|"
else:
text += f"отсортированый массив => {list[index]}, "
print(text)
def bubble_sort(list: list) -> list:
count = 1
sortedCount = len(list) - 1
while count != 0:
count = 0
for index in range(len(list)):
if index < len(list) - 1:
if list[index] > list[index + 1]:
list[index] += list[index + 1]
list[index + 1] = list[index] - list[index + 1]
list[index] = list[index] - list[index + 1]
count += 1
if count != 0:
sortedCount -= 1
else:
sortedCount = 0
printSortedList(list, sortedCount)
return list