feat: implement sorting algorithms in Python

This commit is contained in:
2026-04-12 03:00:46 +03:30
commit d0b7968cb2
5 changed files with 114 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
def selection_sort(arr):
n = len(arr)
for i in range(n - 1):
# Assume the current element is the smallest
min_index = i
# Checking the rest of the array to find the smallest one
for j in range(i + 1, n):
if arr[j] < arr[min_index]:
min_index = j # Update the index of the smallest number
# If the smallest number is not the first, replace
if min_index != i:
arr[i], arr[min_index] = arr[min_index], arr[i]
# Example:
nums = [5, 2, 4, 6, 1, 3]
print("Before sorting:", nums)
selection_sort(nums)
print("After sorting:", nums)