def selectionSort(list):  
   for fillslot in range(len(list)-1,0,-1):  
       maxpos=0  
       for location in range(1,fillslot+1):  
           if list[location]>list[maxpos]:  
               maxpos = location  
  
       temp = list[fillslot]  
       list[fillslot] = list[maxpos]  
       list[maxpos] = temp  
  
list = [88,75,12,98,2,47,22,39,41,7,89,71,99]
selectionSort(list)  
print(list)

Output :

[2, 7, 12, 22, 39, 41, 47, 71, 75, 88, 89, 98, 99]

Add a Comment

Add a Comment