Advertisement
naren_paste

selection_sort

Feb 12th, 2024
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | Source Code | 0 0
  1. def selection_sort(arr):
  2.     for i in range(1, len(arr)):
  3.         v = arr[i]
  4.         j = i
  5.         while j >= 1 and arr[j-1] > v:
  6.             arr[j] = arr[j-1]
  7.             j -= 1
  8.         arr[j] = v
  9.  
  10. # Example usage:
  11. arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
  12. selection_sort(arr)
  13. print(arr)
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement