Python - Selection Sort Algorithm Implementation ~ Your Own Linux..!

PHOTO EMBED

Sat Oct 09 2021 15:54:11 GMT+0000 (Coordinated Universal Time)

Saved by @Adam101 #python

def selection_sort(array):
    n = len(array)
    
    for i in range(n):
        
        # Index of smallest element
        min_index = i
        
        for j in range(i+1, n):
            if array[j] < array[min_index]:
                min_index = j
                
        array[min_index], array[i] = array[i], array[min_index]
        
my_array = [5, 3, 7, 1, 4, 8, 2, 6]
selection_sort(my_array)
print my_array
content_copyCOPY

selection sort that works

http://www.yourownlinux.com/2017/06/python-selection-sort-algorithm.html