Sort the given set of numbers using Selection Sort. The first line of the input contains the number of elements, the second line of the input contains the numbers to be sorted. In the output print the status of the array at the 4th iteration and the final sorted array in the given format
OUTPUT:
TC = 1(1 11 25 65 47) and TC = 2 (1 9 14 47 83 77 25)
Tags languages PYTHONSubscribe Our Newsletter
a=[]
ReplyDeleten=int(input())
for i in range(0,n):
b=int(input())
a.append(b)
i = 0
while i<len(a):
#smallest element in the sublist
smallest = min(a[i:])
#index of smallest element
index_of_smallest = a.index(smallest)
#swapping
a[i],a[index_of_smallest] = a[index_of_smallest],a[i]
i=i+1
if(i==3):
print(" ".join(map(str,a)))
print("Sorted Array")
print(" ".join(map(str,a)))