Created
August 5, 2022 11:41
-
-
Save ioanzicu/6bcc4d4e58cf8c53265e095b4cd2dd05 to your computer and use it in GitHub Desktop.
Selections sort in Python 3 - classic implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selection_sort(nums): | |
for i in range(len(nums)): | |
minim_index = i | |
for j in range(i + 1, len(nums)): | |
if nums[minim_index] > nums[j]: | |
minim = nums[j] | |
minim_index = j | |
nums[i], nums[minim_index] = nums[minim_index], nums[i] | |
return nums | |
nums = [1, 22, 3, 43, 5] | |
res = selection_sort(nums) | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment