Skip to content

Commit 5e50dfd

Browse files
Merge pull request #1 from abdullahmir007/abdullahmir007-patch-1
Create Selection sort.py
2 parents 7a066e4 + a4b675a commit 5e50dfd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Selection sort.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def selection_sort(arr):
2+
n = len(arr)
3+
# Traverse through all array elements
4+
for i in range(n):
5+
# Find the minimum element in the remaining unsorted array
6+
min_index = i
7+
for j in range(i+1, n):
8+
if arr[j] < arr[min_index]:
9+
min_index = j
10+
# Swap the found minimum element with the first element
11+
arr[i], arr[min_index] = arr[min_index], arr[i]
12+
13+
# Taking user input for the list
14+
user_input = input("Enter elements of the list separated by space: ")
15+
input_list = list(map(int, user_input.split()))
16+
17+
# Sorting the user input list using selection_sort function
18+
selection_sort(input_list)
19+
20+
# Displaying the sorted list
21+
print("Sorted Array:", input_list)

0 commit comments

Comments
 (0)