KnowledgeBoat Logo
|

Computer Science

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.

Python Sorting

13 Likes

Answer

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("Partially sorted list after three passes of Bubble sort:")
print(numList)
Output
Partially sorted list after three passes of Bubble sort:
[3, 7, 10, 1, 4, 11, 5, 17, 21, 23]

Answered By

9 Likes


Related Questions