def selection_sort(array, size):
for i in range(0,size-1):
min = array[i]
min_index = i
for j in range(i+1, size):
if min > array[j]:
min = array[j]
min_index = j
#Swapping
array[i],array[min_index] = array[min_index], array[i]
if __name__ == "__main__":
array = ["Rakshit", "Anil", "Partho", "Dipu", "Shreya"]
print("Before sorting list of string is: ")
for i in range(len(array)):
print(i, ":", array[i])
print("After sorting: ")
selection_sort(array,len(array))
for i in range(len(array)):
print(i, ":", array[i])
Comments
Post a Comment
If you've any doubts, please let me text