Descending selection sort Implementation

PHOTO EMBED

Tue Jun 18 2024 03:23:20 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds #python

#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)
content_copyCOPY

https://www.pynerds.com/data-structures/implement-selection-sort-in-python/