# Program to implement the Selection sort algorithm:
n=input("Enter the no. of terms:")
n=int(n)
x=[]
m=0
for i in range (0,n):
m1=input("Enter the no."+str(i+1)+":")
m1=float(m1)
x.append(m1)
for i in range (0,n):
a=i
s=x[i]
for j in range (i+1,n):
if s>x[j]:
a=j
s=x[j]
t=x[i]
x[i]=x[a]
x[a]=t
m=m+1
print("Selection sort of entered no. in ascending order is:\n",x,"\nNo of steps required:",m)
n=input("Enter the no. of terms:")
n=int(n)
x=[]
m=0
for i in range (0,n):
m1=input("Enter the no."+str(i+1)+":")
m1=float(m1)
x.append(m1)
for i in range (0,n):
a=i
s=x[i]
for j in range (i+1,n):
if s>x[j]:
a=j
s=x[j]
t=x[i]
x[i]=x[a]
x[a]=t
m=m+1
print("Selection sort of entered no. in ascending order is:\n",x,"\nNo of steps required:",m)
Comments
Post a Comment