Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

Selection Sort #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions AniruddhaM1396/Selection_sort.py
Original file line number Diff line number Diff line change
@@ -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)