Skip to content

Create Selection sort.py #1

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

Merged
merged 1 commit into from
Oct 28, 2023
Merged
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
21 changes: 21 additions & 0 deletions Selection sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def selection_sort(arr):
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Find the minimum element in the remaining unsorted array
min_index = i
for j in range(i+1, n):
if arr[j] < arr[min_index]:
min_index = j
# Swap the found minimum element with the first element
arr[i], arr[min_index] = arr[min_index], arr[i]

# Taking user input for the list
user_input = input("Enter elements of the list separated by space: ")
input_list = list(map(int, user_input.split()))

# Sorting the user input list using selection_sort function
selection_sort(input_list)

# Displaying the sorted list
print("Sorted Array:", input_list)