Skip to content
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)