#descending selection sort
def selection_sort(lst):
for i in range(len(lst)):
smallest = i
for j in range(i + 1, len(lst)):
if lst[j] > lst[smallest]:
smallest = j
lst[i], lst[smallest] = lst[smallest], lst[i] #swap the elements
#sort a list
L = [99, 9, 0, 2, 1, 0, 1, 100, -2, 8, 7, 4, 3, 2]
selection_sort(L)
print("The sorted list is: ", L)
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