selection sort

PHOTO EMBED

Tue May 07 2024 08:03:14 GMT+0000 (Coordinated Universal Time)

Saved by @jass855

n = int(input('Total number of items in list: '))
L = []

# Input items into the list
for i in range(n):
    item = int(input('Enter the item: '))
    L.append(item)

# Selection sort algorithm
for i in range(n - 1):
    min_index = i

    for j in range(i + 1, n):
        if L[j] < L[min_index]:
            min_index = j

    L[i], L[min_index] = L[min_index], L[i]

# Print the sorted list
print('Sorted list:\n', L)
content_copyCOPY

https://chatgpt.com/c/f7aca05f-2e9f-4596-ba4e-ae1b91e73435