Python program to Sort Array Using Selection Sorting

from random import randint
x = 20
y = []
for i in range(20):
 y.append(randint(1,20))
print(y)
j = x-1
while j != 0:
 k = 0
 for i in range(1, j+1):
    if y[i] > y[k]:
        k = i
 z = y[k]
 y[k] = y[j]
 y[j] = z
 j -= 1
print(y)

 

 

 

Output:

[14, 3, 13, 8, 12, 8, 14, 9, 13, 18, 19, 15, 16, 9, 16, 14, 18, 6, 3, 12]
[3, 3, 6, 8, 8, 9, 9, 12, 12, 13, 13, 14, 14, 14, 15, 16, 16, 18, 18, 19]

 

[10, 3, 4, 8, 5, 17, 3, 2, 1, 10, 12, 18, 13, 10, 4, 4, 6, 15, 8, 19]
[1, 2, 3, 3, 4, 4, 4, 5, 6, 8, 8, 10, 10, 10, 12, 13, 15, 17, 18, 19]

 

Subscribe For Daily Updates