Selection sort

# Selection sort


def fnSelectionsort(L):

for i in range(0,len(L)-1):

min_pos=i

min_ele=min(L[i+1:])

if(L[min_pos] > min_ele):

min_ele_pos = L.index(min_ele)

L[min_pos],L[min_ele_pos]=L[min_ele_pos],L[min_pos]

L = eval(input("Enter list of elements : "))

fnSelectionsort(L)

print(L)


"""

Sample output

>python Selectionsort.py

Enter list of elements : [34,8,64,51,32,21]

[8, 21, 32, 34, 51, 64]

"""

No comments:

Post a Comment

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

Anu