We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 7a066e4 + a4b675a commit 5e50dfdCopy full SHA for 5e50dfd
Selection sort.py
@@ -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