def selectionSort(List):

for i in range(len(List) - 1): #For iterating n - 1 times

minimum = i

for j in range( i + 1, len(List)): # Compare i and i + 1 element

if(List[j] < List[minimum]):

minimum = j

if(minimum != i):

List[i], List[minimum] = List[minimum], List[i]

return List

if __name__ == '__main__':

List = [4,6,9,8,1,7,3]

print('Sorted List:',selectionSort(List))

#clcoding.com

Sorted List: [1, 3, 4, 6, 7, 8, 9]

## 0 Comments:

## Post a Comment