Q. Consider a list of 10 elements:
numList =[7, 11, 3, 10, 17, 23, 1, 4, 21, 5].
Display the partially sorted list after three complete passes of Bubble sort.
Answer :-
We should write this code:-
numList = [7,11,3,10,17,23,1,4,21,5]
n = len(numList)
for i in range(3):
for j in range(0, n-i-1):
if numList[j] > numList[j+1] :
numList[j], numList[j+1] = numList[j+1], numList[j]
print(numList)
Output:-
[3, 7, 10, 1, 4, 11, 5, 17, 21, 23]
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )