I have a question about Python.In order to execute bubble sort, I have programmed as follows, but I would like to print every time after operation.What should we do to do so?
For example, if [3,5,1,7] is given,
[3,5,1,7]
[3,1,5,7]
[1,3,5,7]
I would like to extract it
def BubbleSort(num):
for i in range (len(num)):
for jin range (len(num)-1, i, -1):
if num[j]<num[j-1]:
num[j], num[j-1] = num[j-1], num[j]
return num
def BubbleSort(num):
print(num)
for i in range (len(num)) :
for jin range (len(num)-1, i, -1):
if num[j]<num[j-1]:
num[j], num[j-1] = num[j-1], num[j]
print(num)
return num
if__name__=='__main__':
BubbleSort ([3,5,1,7])
# [3, 5, 1, 7]
# [3, 1, 5, 7]
# [1, 3, 5, 7]
© 2024 OneMinuteCode. All rights reserved.