Sorting - Selection sort

# Selection sort

# Read elements and create list

no_of_terms = int(input("Enter number of terms : "))
List1 = []

for idx in range(0, no_of_terms, 1):
    ele = int(input("Enter element : "))
    List1.append(ele)

print("Original list :", List1)

for idx in range(0, len(List1)-1, 1):
    min_ele = min(List1[idx:len(List1)])
    pos = List1.index(min_ele)
    if(pos != idx):   
        List1[pos], List1[idx]  = List1[idx], List1[pos]
       
print("Sorted List :", List1)

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu