TD4_DEV51_schied/sort_algorithm.py

21 lines
794 B
Python

def sort_func(array):
if(not isinstance(array[0], list)):
for i in range(len(array)):
for j in range(0, len(array)-i-1):
if array[j] > array[j+1]:
array[j], array[j+1] = array[j+1], array[j]
return (array, [sum(array)])
else:
res = [[], []]
for arr in array:
arrRes = sort_func(arr)
res[0].append(arrRes[0])
res[1].append(arrRes[1][0])
for i in range(len(res[0])-1):
if(res[1][i] > res[1][i+1]):
res[0][i], res[0][i+1] = res[0][i+1], res[0][i]
res[1][i], res[1][i+1] = res[1][i+1], res[1][i]
res[1] = [sum(res[1])]
return (res[0], res[1])
print(sort_func([[0,3,2], [9,4,5], [4,1,3]])[0])