last lab
This commit is contained in:
32
labPython/lab7/sort_methods.py
Executable file
32
labPython/lab7/sort_methods.py
Executable file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
Reference in New Issue
Block a user