def bubbleSort(List):
for i in range(len(List)):
for j in range(len(List) - 1, i, -1):
if List[j] < List[j - 1]:
List[j], List[j - 1] = List[j - 1], List[j]
return List
if __name__ == '__main__':
List = [7,1,8,2,9,4,6,5]
print('Sorted List:',bubbleSort(List))
#clcoding.com
Sorted List: [1, 2, 4, 5, 6, 7, 8, 9]
0 Comments:
Post a Comment