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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter