From dd1524dceb784f086ba508015fca20d6e810726a Mon Sep 17 00:00:00 2001 From: AniruddhaM1396 Date: Tue, 3 Oct 2023 22:31:30 +0530 Subject: [PATCH] Selection Sort --- AniruddhaM1396/Selection_sort.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 AniruddhaM1396/Selection_sort.py diff --git a/AniruddhaM1396/Selection_sort.py b/AniruddhaM1396/Selection_sort.py new file mode 100644 index 0000000..9076b94 --- /dev/null +++ b/AniruddhaM1396/Selection_sort.py @@ -0,0 +1,19 @@ +def selection_sort(array): + # Looping through every element of the array + for i in range(len(array)): + + # Searching the minimum element in the remaining subarray + min_ind = i + for j in range(i + 1, len(array)): + if array[min_ind] > array[j]: + min_ind = j + + # Swaping the minimum element and the first element + array[i], array[min_ind] = array[min_ind], array[i] + +array = [23, 42, 3, 83, 36, 49, 19] + +selection_sort(array) + +print("The sorted array is: ") +print(array) \ No newline at end of file