Skip to content

selection__sort #12156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sorts/selection__sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def selectionSort(array, size):

Check failure on line 1 in sorts/selection__sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

sorts/selection__sort.py:1:5: N802 Function name `selectionSort` should be lowercase

Check failure on line 1 in sorts/selection__sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

sorts/selection__sort.py:1:5: N802 Function name `selectionSort` should be lowercase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file sorts/selection__sort.py, please provide doctest for the function selectionSort

Please provide return type hint for the function: selectionSort. If the function does not return a value, please provide the type hint as: def function() -> None:

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: selectionSort

Please provide type hint for the parameter: array

Please provide type hint for the parameter: size

for s in range(size):
min_idx = s

for i in range(s + 1, size):
# For sorting in descending order
# for minimum element in each loop
if array[i] < array[min_idx]:
min_idx = i

# Arranging min at the correct position
(array[s], array[min_idx]) = (array[min_idx], array[s])


data = [7, 2, 1, 6]
size = len(data)
selectionSort(data, size)

print("Sorted Array in Ascending Order is :")
print(data)
Loading