fork download
  1. def selection_sort(arr):
  2. n = len(arr)
  3. for i in range(n - 1):
  4. min_idx = i
  5. for j in range(i + 1, n):
  6. if arr[j] < arr[min_idx]:
  7. min_idx = j
  8. arr[i], arr[min_idx] = arr[min_idx], arr[i]
  9. print("Lista ordenada:", arr)
  10.  
  11. lista = [3, 1, 4, 5, 2]
  12. selection_sort(lista)
  13.  
Success #stdin #stdout 0.01s 7076KB
stdin
Standard input is empty
stdout
('Lista ordenada:', [1, 2, 3, 4, 5])