def bubbleSort(src_list, flag_value):
'''
the bisection is helpful to come ture which is sort
:param src_list:
:param flag_value: “dataup” is sort by ascending; "datadown" is sort by descending
:return:
'''
src_len = len(src_list)
if ("dataup" == flag_value):
for i in range(src_len):
for j in range(src_len):
if src_list[i] < src_list[j]:
mid_size = src_list[i]
src_list[i] = src_list[j]
src_list[j] = mid_size
elif ("datadown" == flag_value):
for i in range(src_len):
for j in range(src_len):
if src_list[i] > src_list[j]:
mid_size = src_list[i]
src_list[i] = src_list[j]
src_list[j] = mid_size
else:
print("error")
return src_list
if __name__ == '__main__':
ret = bubbleSort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95],"dataup")
print(ret)
ret1 = bubbleSort([-2, -5, -45],"dataup")
print(ret1)